#include <bits/stdc++.h>

using namespace std;

long long T,A,B;

int main()
{
    cin>>T;
    
    for(int t=1; t<=T; t++)
    {
        cin>>A>>B;
        if(B%2==0)
        {
            for(int x=1; x<=sqrt(A); x+=2)
            {
                if(A%x==0 and ((A/x)^x)==B)
                {
                    cout<<x<<" "<<A/x<<endl;
                    break;
                }
                if(x+2>sqrt(A))
                {
                    cout<<-1<<endl;
                    break;
                }
            }
        }
        if(B%2==1)cout<<-1<<endl;
    }
    return 0;
}