/**
Author : Abdullah Al Mahdi
CF Handle: abdmahdi56
Leading University,Sylhet
Submitted on:
*/
#include <bits/stdc++.h>
#define endl '\n'
#define yes cout << "YES\n"
#define no cout << "NO\n"
#define ll long long
#define vi vector<ll>
#define all(v) v.begin(), v.end()
#define loop(i,n) for(int (i) = 0; (i) < (n); (i)++)
using namespace std;
void Bismillah() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
}
void solve() {
int x,y;
cin>>x>>y;
int ans=min(x,y)+1;
bool ok=true;
if(x==1 || y==1){
cout<<-1<<endl;
return ;
}
while(ok){
if(ans %x!=0 && ans%y!=0 && ans<=100){
ok =false;
cout<<ans<<endl;
}else ans++;
}
}
int main() {
Bismillah();
int t;
cin >> t;
while (t--) {
solve();
}
return 0;
}