#include<bits/stdc++.h>
using namespace std;
vector<vector<long long> > dp(2000,vector<long long>(2000,-1));
long long solve(long long i,long long j,int last){
if(i<=0||j<=0)return 0;
if(dp[i][j]!=-1)return dp[i][j];
if(last!=0){
return dp[i][j]= 1 + solve(i+3,j+2,0);
}
return dp[i][j]= 1 + max(solve(i-5,j-10,1),solve(i-20,j+5,2));
}
int main(){
ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
int t;
cin>>t;
while(t--){
long long h,a;
cin>>h>>a;
cout<<solve(h+3,a+2,0)<<"\n";
}
return 0;
}
I2luY2x1ZGU8Yml0cy9zdGRjKysuaD4KdXNpbmcgbmFtZXNwYWNlIHN0ZDsKdmVjdG9yPHZlY3Rvcjxsb25nIGxvbmc+ID4gZHAoMjAwMCx2ZWN0b3I8bG9uZyBsb25nPigyMDAwLC0xKSk7CmxvbmcgbG9uZyBzb2x2ZShsb25nIGxvbmcgaSxsb25nIGxvbmcgaixpbnQgbGFzdCl7CglpZihpPD0wfHxqPD0wKXJldHVybiAwOwoJaWYoZHBbaV1bal0hPS0xKXJldHVybiBkcFtpXVtqXTsKCWlmKGxhc3QhPTApewoJCXJldHVybiBkcFtpXVtqXT0gMSArIHNvbHZlKGkrMyxqKzIsMCk7Cgl9CglyZXR1cm4gZHBbaV1bal09IDEgKyBtYXgoc29sdmUoaS01LGotMTAsMSksc29sdmUoaS0yMCxqKzUsMikpOwp9CmludCBtYWluKCl7Cglpb3M6OnN5bmNfd2l0aF9zdGRpbyhmYWxzZSk7Y2luLnRpZShOVUxMKTtjb3V0LnRpZShOVUxMKTsKCWludCB0OwoJY2luPj50OwoJCgl3aGlsZSh0LS0pewoJCWxvbmcgbG9uZyBoLGE7CgkJY2luPj5oPj5hOwoJCWNvdXQ8PHNvbHZlKGgrMyxhKzIsMCk8PCJcbiI7Cgl9CglyZXR1cm4gMDsKfQ==