#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;

//ako je cif=0, to znaci da je nula
void tobit(ll br, vi& niz, int& cif)
{int i, val;
 ll tmp;
 cif=0;
  while(br>0)
  { tmp=br>>1;
    niz[cif] = br-(tmp<<1);
    br=tmp;
    cif++;
  }
  for(i=cif;i<64;i++) niz[i]=0;//cisti ostatak
}

int broj(ll br)
 { int cif=0;
   while(br>0) {br>>=1; cif++;}
   return cif;
 }

void stampa(vi niz, int cif)
{int i;
 for(i=cif-1;i>=0;i--) cout<<niz[i];
}

int main()
{int i, k, m, n, tmp, val, t, cn, bn, an, xn, yn, naso, cif;
 ll a, b, c, lxg, lyg, lval, ltmp, lrasp, lk, lcomp, lbxor;
 vi cbit(64), bbit(64), pbit(64), qbit(64), rbit(64);
 cin>>t;
 for(i=1;i<=t;i++)
 { cin>>a>>b;
   if(((b>>1)<<1)!= b) {cout<<-1<<endl; continue;}//ako je b neparan
   c=sqrt(a); naso=0;
   if(b==0)
     { if(a==(c*c)){cout<<c<<" "<<c<<endl; continue;}//b==0 to znaci da su isti
       else {cout<<-1<<endl; continue;}//nemoguce
     }
   tobit(c, cbit, cn);
   //cout<<endl;
   //stampa(cbit, cn);
   tobit(b, bbit, bn);
   an=broj(a);

   // OVDE OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO
   if(bn>cn)//ako je b vece od korena, x ima nekoliko cifara vise
   { //cout<<"\nUso cn<bn \n";
     cif=bn-cn;
     naso=0;
     lxg=0;
     for(k=1;k<=cif;k++) lxg=(lxg<<1)+bbit[bn-k];//pocetne jedinice
     lxg<<=cn;
     lyg=1;lxg++;//dodatak jedan na kraju
     lbxor=b;
     lval=(b>>cn)<<cn;
     lbxor=b-lval;
     lbxor>>=1;

     for(lk=0;lk<=lrasp;lk++)
     { lcomp=lk^lbxor;
       ltmp=(lxg+(lk<<1))*(lyg+(lcomp<<1)); //proizvod
       if(a==ltmp){naso=1; break;}
     }
     if(naso==1) cout<<lxg+(lk<<1)<<" "<<lyg+(lcomp<<1)<<endl;
     else cout<<"-1\n";

   }

   else if(bn==cn)//y ima jednu cifru manje, a x toliko
   { //cout<<"\nUso cn==bn \n";
     lxg=(1<<(bn-1));//prvo bez 1
     lbxor=(b-lxg)>>1;
     lxg++;
     lyg=1;
     lrasp=(1<<(bn-2))-1;

     for(lk=0;lk<=lrasp;lk++)
     { lcomp=lk^lbxor;
       ltmp=(lxg+(lk<<1))*(1+(lcomp<<1)); //proizvod
       if(a==ltmp){naso=1; break;}
     }
     if(naso==1) cout<<lxg+(lk<<1)<<" "<<lyg+(lcomp<<1)<<endl;
     else cout<<"-1\n";

   }
   else//bn<cn
   { //cout<<"\nUso cn>bn \n";
     cif=cn-bn;
     lxg=0;
     for(k=1;k<=cif;k++) lxg=(lxg<<1)+cbit[cn-k];//zajednicke cifre
     lyg=lxg<<1;//nula
     lxg=lyg+1;//jedan
     lyg<<=bn-1;
     lxg<<=bn-1;
     lrasp=(1<<(bn-2))-1;

     lyg++;lxg++;//dodatak jedan na kraju
     lbxor=(b>>1)-(1<<(bn-2));

     for(lk=0;lk<=lrasp;lk++)
     { lcomp=lk^lbxor;
       ltmp=(lxg+(lk<<1))*(lyg+(lcomp<<1)); //proizvod
       if(a==ltmp){naso=1; break;}
     }
     if(naso==1) cout<<lxg+(lk<<1)<<" "<<lyg+(lcomp<<1)<<endl;
     else cout<<"-1\n";

   }//else
  }//for t
 return 0;
}

/*
1
27 26

5
21 4
9 0
9 2
35 2
513 8


4
21 4
2795079079011879151 119681854
9 0
9 2

3 7
1679133257 1664596343
3 3
-1

  cout<<"\parametri su: \n lrsap = "<<lrasp<<" lbxor = "<<lbxor;
     cout<<"\n lxg = "<<lxg<<" lyg = "<<lyg<<endl;
*/