#include <bits/stdc++.h>

using namespace std;

int main()
{
    long long t,a,b,j2,x;
    cin>>t;
    bool z;

    for(int i=0;i<t;i++)
    {

        cin>>a>>b;
        z=false;
        long long sqrta=sqrt(a);
        for(long long j=1;j<=sqrta;j++)
        {
            if(a%j==0)
            {
                j2=a/j;
                x=j^j2;
                //cout<<resenje<<"\n";

            }
            if(x==b)
            {
                cout<<j<<" "<<a/j<<"\n";
                z=true;
                break;
            }

        }
        if(!z)
            cout<<-1;

    }

    return 0;
}