#include<bits/stdc++.h>
using namespace std;
int main() {
int T;
cin>>T;
while(T--) {
double d,t;
double s1=11,s2=11;
cin>>d>>t;
s1+=2*t/5;
s2+=2.5*t/4;
if(d>3&&d<=10) {
s1+=2*(d-3);
s2+=2.5*(d-3);
} else if(d>10) {
s1+=2*7+3*(d-10);
s2+=2.5*7+3.75*(d-10);
}
double r=(int)(s2+0.5)-(int)(s1+0.5);
printf("%.0f\n",r);
}
return 0;
}