#include <iostream>
using namespace std;
int f()
{
    long long int t,a,b;
    cin>>t;
    for(int i=0;i<t;i++)
    {
        cin>>a>>b;
        int ind=0;
        for(int j=1;j*j<=a;j+=2)
            if(a%j==0)
                if((j^(a/j))==b)
                {
                    cout<<j<<" "<<a/j<<endl;
                    ind=1;
                    break;
                }
        if(!ind)
            cout<<-1;
    }
    return 0;
}
int main()
{
    f();
}