/*
统计硬币
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 2495 Accepted Submission(s): 1726
#include<iostream>
using namespace std;
int main()
{
int a;
cin>>a;
int n,m,tag,i,j,k,num;
while(a--)
{
num=0;
cin>>n>>m;
tag=0;
for(i=0;i<=n;i++)
{
if((num+1>m)&&(i!=0))
break;
for(j=0;j<=n;j++)
{
if((2+num>m)&&(j!=0))
break;
for(k=0;k<=n;k++)
{
if((i*1+j*2+k*5)==m&&((i+j+k)==n))
num++;
if((i*1+j*2+k*5)>m)
break;
}
}
}
cout<<num<<endl;
num=0;
}
return 0;
}