#include using namespace std; #define REP(i,m,n) for(int i=(m);i<(n);i++) #define rep(i,n) REP(i,0,n) #define pb push_back #define mp make_pair #define all(c) (c).begin(),(c).end() #define rall(c) (c).rbegin(),(c).rend() #define double long double typedef long long ll; typedef pair pii; typedef pair pll; const ll inf=1e9+7; const ll mod=1e9+7; ll gcd(ll a,ll b){ if(min(a,b)==0)return max(a,b); if(max(a,b)%min(a,b)==0)return min(a,b); else return gcd(min(a,b),max(a,b)%min(a,b)); } int main(){ ll q;cin>>q; while(q){ q--; ll n,k;cin>>n>>k; ll cnt=0; ll ans=-1; ll t=1; if(k==1)ans=n-1; else{ while(cnt