#include <bits/stdc++.h>
using namespace std;
string bin (long long n, string s)
{
    if (n==0)
    {
        s.push_back('0');
        return s;
    }
    else
    {
        while (n>0)
    {
        if (n%2==0)
            s.push_back('0');
        else
            s.push_back('1');
        n/=2;
    }
    reverse(s.begin(), s.end());
    return s;
    }
}
int dekadni (string s)
{
    int n=(s.size()-1);
    long long br=0, p=1;
    for (int i=n; i>=0; i--)
    {
        if (s[i]=='1')
            br+=p;
        p*=2;
    }
    return br;
}


int main()
{
    int t;
    cin>>t;
    for (int i=0; i<t; i++)
    {
        long long a, b;
        cin>>a>>b;
        int q=1;
        string s=bin(b,"");
        for (int k=1; k<=sqrt(a); k++)
        {
            q=1;
            if (a%k==0)
            {
            string x=bin(k,"");
            string y=bin(a/k,"");
            int br=s.size();
            int br1=x.size();
            int br2=y.size();
            int najv=max(br,br1);
            najv=max(najv,br2);
            for (int p=br; p<najv; p++)
                s='0'+s;
            for (int p=br1; p<najv; p++)
                x='0'+x;
            for (int p=br2; p<najv; p++)
                y='0'+y;
            for (int j=0; j<najv; j++)
            {
                if (abs((x[j]-'0')-(y[j]-'0')!=s[j]-'0'))
                    q=0;
            }
            if (q==1)
            {
                cout<<k<<" "<<a/k<<endl;
                break;
            }

            }
        }
        if (q==0)
            cout<<-1<<endl;
    }
}