#include<iostream>
#include<algorithm>
using namespace std;
bool comp(int a,int b)
{
return a>b;
}
int main()
{
int T,d,t,a,b;
double fee;
scanf("%d",&T);
while(T--)
{
scanf("%d %d",&d,&t);
double f1,f2;
f1=f2=11;
if(d<=10&&d>3)
f1+=(d-3)*2,f2+=(d-3)*2.5;
else if(d>10)
f1+=14+(d-10)*3,f2+=17.5+(d-10)*3.75;
f1+=(t*1.0/5)*2,f2+=(t*1.0/4)*2.5;
a=(int)(f1+0.5),b=(int)(f2+0.5);
printf("%d\n",b-a);
}
}