#include <bits/stdc++.h>
using namespace std;
struct node
{
double n, v, p;
bool operator<(const node &b) const
{
return p > b.p;
}
} a[10005];
int k, s;
double w;
int main()
{
cin >> k;
while (k--)
{
cin >> w >> s;
for (int i = 1; i <= s; i++)
{
cin >> a[i].n >> a[i].v;
a[i].p = a[i].v / a[i].n;
}
sort(a + 1, a + s + 1);
double sum = 0;
for (int i = 1; i <= s; i++)
{
if (w >= a[i].n)
{
w -= a[i].n;
sum += a[i].v;
}
else
{
sum += a[i].p * w;
break;
}
}
printf("%.2lf\n", sum);
}
return 0;
}