#include<stdio.h> int main() { int t; scanf("%d",&t); while(t--) { int i,x,q,t,k,p; double ans; scanf("%d",&x); scanf("%d",&q); for(i=0; i<q; i++) { scanf("%d %d",&p,&t); switch(p) { case 1: ans=(double)(60-x)*t; break; case 2: ans=(double)t*3600/(60-x); break; case 3: ans=(double)2592000.00/x*t; break; default: break; } printf("%.2lf\n",ans); } } return 0; }