#include <bits/stdc++.h>

using namespace std;

int main() 
{
  ios::sync_with_stdio(0);
  cin.tie(0);
  long long a,b,t,i,j,x,y,o1,o2;
  cin>>t;
  for(i=0;i<t;i++)
  {
    cin>>a>>b;
    o1=o2=-1;
    for(j=1;j<=a;j++)
    {
      x=j;
      y=a/x;
      if(b==(x^y))
      {
        o1=x;
        o2=y;
        break;
      }
    }
    if(o1==-1&&o2==-1)
    {
      cout<<"-1";
    }
    else
    {
      cout<<o1<<" "<<o2<<"\n";
    }
  }
}