#include <iostream>
#include<algorithm>
#include<cmath>
using namespace std;

int main()
{
    ios::sync_with_stdio(false);
    long long int t,x,y,a,b,k,p,r;

    cin>>t;
    while(t--)
    {
        cin>>p>>x;  r=-1;

        a=1;
        while(a*a<=p)
        {
            if(p%a==0)
            {
                b=p/a;
                if((a^b)==x) {r=1; break;}
            }
            a+=2;
        }

        if(r==-1) cout<<r<<endl;
        else cout<<a<<" "<<b<<endl;

    }

    return 0;
}