#include <iostream>
#include <cmath>

using namespace std;

int main()
{
    long long a,b,x,y,p,q;
    int t;
    cin>>t;
    while(t--)
    {
        cin>>a>>b;
        if(b==0)
            if(int(sqrt(a))*int(sqrt(a))==a)
                cout<<int(sqrt(a))<<" "<<int(sqrt(a))<<endl;
            else
                cout<<-1<<endl;
        else
        {
            if(b==1)
                cout<<-1<<endl;
            else{
                x=1;
                while(x*x<=a)
                {
                    if(a%x==0&&(x^(a/x))==b)
                        break;
                    x+=2;
                }
                if(a%x==0&&x^(a/x)==b)
                    cout<<x<<" "<<a/x<<endl;
                else
                    cout<<-1<<endl;
            }
        }
    }
}