#include <iostream>

using namespace std;

long long bin(long long x)
{
    long long g=x;
    int k=1;
    long long binarni=0;
    while(g>0)
    {
       binarni+=k*(g%2);
       g/=2;
       k*=10;
    }

    return binarni;

}
int velicina(long long binarnox)
{

    int d=0;
    while(binarnox>0)
    {
        binarnox/=10;
        d++;
    }

    return d;
}

long long xxor(long long binarx,long long binary)
{
    int k=1;
    long long c=0;

    if(velicina(binarx)>velicina(binary))
    {
       long long p[velicina(binarx)];
       long long s[velicina(binarx)];
        for(int i=velicina(binarx);i>0;i--)
        {
            p[i]=binarx%10;
            s[i]=binary%10;
            if(p[i]==s[i])
            {
                binarx/=10;
                binary/=10;
                k*=10;
            }
            else
            {
                c+=k;
                binarx/=10;
                binary/=10;
                k*=10;
            }

        }

    }
    else{
        long long p[velicina(binary)];
       long long s[velicina(binary)];
        for(int i=velicina(binary);i>0;i--)
        {
            p[i]=binarx%10;
            s[i]=binary%10;
             for(int i=velicina(binary);i>0;i--)
        {
            p[i]=binarx%10;
            s[i]=binary%10;
            if(p[i]==s[i])
            {
                binarx/=10;
                binary/=10;
                k*=10;
            }
            else
            {
                c+=k;
                binarx/=10;
                binary/=10;
                k*=10;
            }

        }
        }

    }
    return c;

}
bool ispitaj(long long x,long long y,long long b)
{
    if(xxor(bin(x),bin(y))==bin(b))
    {
        return true;
    }
    else
      {
          return false;
      }
}
void proveri(long long a,long long b)
{
    bool p=false;
    for(int i=1;i<=a/2;i++)
    {
        long long x=i;
        if(a%i==0)
        {
            int y=a/i;
            if(ispitaj(x,y,b))
            {
                cout<<x<<" "<<y<<endl;
                p=true;
                break;
            }
        }
    }
    if(p==false)
   {
       cout<<-1;
   }
}
int main()
{
   int t;
   cin>>t;
   long long a[t];
   long long b[t];
   for(int i=0;i<t;i++)
   {
       cin>>a[i]>>b[i];
   }
   for(int i=0;i<t;i++)
   {
       proveri(a[i],b[i]);
   }
}