#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <set>
#include <cstring>
#include <stack>
#include <set>
#include <vector>
#include <queue>
#define Swap(a,b) a ^= b ^= a ^= b
#define cl(a,b) memset(a,b,sizeof(a))
using namespace std ;
typedef long long LL;
const int N = 1e7+10 ;
const int MAX = 105;
const int inf = 0xffffff;
const LL mod = 1e9+7 ;
LL gcd(LL a,LL b){return b?gcd(b,a%b):a;}
LL lcm(LL a,LL b){return a/gcd(a,b)*b;}
priority_queue<int,vector<int>,greater<int> > q ;// 小跟堆
priority_queue<int> Q ; // 大堆
int ans ;
void dfs(int wine , int store , int flower , int state){
if(store ==0 && flower==0&& state){
if(wine == 0 ){
ans++ ;
}
return ;
}
else{
if(store > 0&& wine >0 ){
dfs(wine*2 ,store-1,flower,0) ;
}
if(flower >0 && wine >0){
dfs(wine-1,store,flower-1,1) ;
}
}
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL),cout.tie(NULL);
int T;
cin >>T;
while(T--){
int wine = 2 ;
int m , n ;
cin >>m >>n ;// 店的次数, 花的次数
dfs(wine,m,n,0);
cout<<ans<<endl;
}
return 0;
}