#include <iostream>
#include <cmath>
using namespace std;
long long int f(long long int x,long long int y)
{
    long long int c;
    for(long long int i=1;i<=x/2;i++)
    {
            if(x%i==0)
            {
                      c=i^(x/i);
                      if(c==y) return i;
            }
            if(i==x/2) return 0;
    }
}
int main()
{
    
    int t;
    cin>>t;
    long long int a[t],b[t];
    for(int i=0;i<t;i++)
    {
        cin>>a[i]>>b[i];
    }
    
    for(int i=0;i<t;i++)
    {
            if(f(a[i],b[i])==0) cout<<-1<<endl;
            else
        cout<<f(a[i],b[i])<<" "<<a[i]/f(a[i],b[i])<<endl;
                 
    }
    
    
    return 0;
}