#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
const ll MOD = 1e9+7;
int t;
ll a,b;
int main()
{
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    cin>>t;

    while(t--){
        cin>>a>>b;
        bool found=false;

        for(ll i=1;i*i<=a;i+=2LL){
            if(a%i==0LL){
                ll luxor=(a/i)^i;
                if(luxor==b){
                    found=true;
                    cout<<i<<" "<<a/i<<"\n";
                }
            }
            if(found)break;
        }
        if(!found)cout<<-1<<"\n";
    }

    return 0;
}