#include "iostream"
#include "stdlib.h"
#include "string.h"
typedef struct{
int p;
int w;
}rice;
int cmp(const void *a,const void *b)
{
rice *c=(rice *)a;
rice *d=(rice *)b;
return c->p-d->p;
}
int main()
{
int n,m;
int c;
rice r[1005];
scanf("%d",&c);
while(c--)
{
scanf("%d%d",&n,&m);
for(int i=0;i<m;i++)
{
scanf("%d%d",&r[i].p,&r[i].w);
}
qsort(r,m,sizeof(rice),cmp);
int i=0;
double sum=0;
while(r[i].p*r[i].w<=n&&i<m)
{
sum+=(double)r[i].w;
n=n-r[i].w*r[i].p;
i++;
}
if(i<m&&n>0)
sum+=(double)n/r[i].p;
printf("%.2lf\n",sum);
}
return 0;
}