#include <bits/stdc++.h>
using namespace std;
int main()
{
int T;
cin>>T;
while(T--)
{
int n,m;
cin>>n>>m;
if(n>m)
swap(n,m);
if(n==1)
cout<<2+m%2<<endl;
else
cout<<0<<endl;
}
}