#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 naciX (string b, long long a, string x, string y, int br)
{
    int t=b.size();
    if (br==t)
    {
        int p=dekadni(x);
        int q=dekadni(y);
        if ((p*q)==a)
              return p;
    }
    else
    {
        if (b[br]=='0')
        {
            x[br]='0';
            y[br]='0';
            naciX(b,a,x,y,br+1);
            x[br]='1';
            y[br]='1';
            naciX(b,a,x,y,br+1);
        }
        else
        {
            x[br]='1';
            y[br]='0';
            naciX(b,a,x,y,br+1);
            x[br]='0';
            y[br]='1';
            naciX(b,a,x,y,br+1);
        }
    }
}
int main()
{
    int k;
    cin>>k;
    for (int j=0; j<k; j++)
    {
    long long a, b,p;
    cin>>a>>b;
    string rez="", x, y;
    rez=bin(b,rez);
    int br=rez.size();
    for (int i=0; i<br; i++)
    {
        x.push_back('0');
        y.push_back('0');
    }
    if (b==0)
    {
        int t=sqrt(a), g=1;
        string s=bin(t,"");
        for (int i=0; i<s.size(); i++)
        {
            if (s[i]!='1')
                {
                    g=0;
                    break;
                }
        }
        if (g==1)
            cout<<t<<" "<<t<<endl;
        else
            cout<<-1<<endl;
    }
    else
    {
    p=naciX(rez,a,x,y,0);
    if (p==-1)
        cout<<-1<<endl;
    else
    cout<<p<<" "<<a/p<<endl;
    }
}
}