#include <iostream>
#include<bits/stdc++.h>
using namespace std;
int dp[2000][2000];
int count(int cur,int h,int a)
{
if(h<=0||a<=0)
return 0;
if(dp[h][a]!=-1)
return dp[h][a];
if(cur)
return(count(0,h+3,a+2)+1);
dp[h][a]=max(count(1,h-5,a-10),count(1,h-20,a+5))+1;
return dp[h][a];
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int t,h,a;
memset(dp,-1,sizeof(dp));
cin>>t;
while(t--)
{
cin>>h>>a;
cout<<count(0,h+3,a+2)<<"\n";
}
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZTxiaXRzL3N0ZGMrKy5oPgoKdXNpbmcgbmFtZXNwYWNlIHN0ZDsKaW50IGRwWzIwMDBdWzIwMDBdOwppbnQgY291bnQoaW50IGN1cixpbnQgaCxpbnQgYSkKewogICAgaWYoaDw9MHx8YTw9MCkKICAgICAgICByZXR1cm4gMDsKICAgIGlmKGRwW2hdW2FdIT0tMSkKICAgICAgICByZXR1cm4gZHBbaF1bYV07CiAgICBpZihjdXIpCiAgICAgICAgcmV0dXJuKGNvdW50KDAsaCszLGErMikrMSk7CiAgICBkcFtoXVthXT1tYXgoY291bnQoMSxoLTUsYS0xMCksY291bnQoMSxoLTIwLGErNSkpKzE7CiAgICByZXR1cm4gZHBbaF1bYV07Cn0KaW50IG1haW4oKSB7CgkKICAgIGlvc19iYXNlOjpzeW5jX3dpdGhfc3RkaW8oZmFsc2UpOwogICAgY2luLnRpZShOVUxMKTsKICAgIGNvdXQudGllKE5VTEwpOwoJaW50IHQsaCxhOwoJbWVtc2V0KGRwLC0xLHNpemVvZihkcCkpOwoJY2luPj50OwoJd2hpbGUodC0tKQoJewoJICAgICBjaW4+Pmg+PmE7CgkgICAgIGNvdXQ8PGNvdW50KDAsaCszLGErMik8PCJcbiI7Cgl9CglyZXR1cm4gMDsKfQo=