#include<iostream>
using namespace std;
int main(){
    int t;
    cin>>t;
    long long int a[t],b[t],x[t],y[t];
    for(int i=0;i<t;i++)
    {
        cin>>a[i]>>b[i];
    }
    for(int i=0;i<t;i++)
    { 
        x[i]=3;
        while(x<=a)
        {
            if(a[i]%x[i]==0 && x[i]^y[i]==b[i])
            {
                y[i]=a[i]/x[i];
                break;
            }
            else
                x[i]+=2;
        }
        if(x[i]>a[i])
            cout<<"-1"<<endl;
        else
            cout<<x[i]<<" "<<y[i]<<endl;
    }
    return 0;
}