#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;
        
        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;
            }
        }
    
    }
    return 0;
}