#include<bits/stdc++.h>
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define pb push_back
#define ll long long int
#define yes cout<<"YES\n"
#define no cout<<"NO\n"
#define mx_ele(v) *max_element(v.begin(),v.end())
#define mnm_ele(v) *min_element(v.begin(),v.end())
#define endl "\n"
using namespace std;
void smile()
{
int m,n;
cin>>m>>n;
int bound=min(m,n);
if(m%2==0 and n%2!=0)
cout<<"-1\n";
else if(m%2!=0 and n%2==0)
cout<<"-1\n";
else
{
if(m%2==0)
{
cout<<2<<endl;
}
else if(m%2!=0)
cout<<3<<endl;
}
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int T=1;
cin>>T;
while(T--)
{
smile();
}
}