#include <bits/stdc++.h>
using namespace std;
#define N
#define ll long long

int t,a,b,flag=0;
int main()
{
    ios::sync_with_stdio(0);cin.tie(0);cerr.tie(0);cout.tie(0);
    cin >> t;
    while(t--){
        cin >> a >> b;
        flag=0;
        if(b&1){
            cout<<"-1\n";
            continue;
        }
        for(int i=3;i<=sqrt(a);i+=2){
            if(a%i==0){
                int c = a/i;
                int p = c^i;
                if(p==b){
                    cout << i << " " << c << "\n";
                    flag=1;
                    break;
                }
            }
        }
        if(!flag)cout<<"-1\n";
    }

    return 0;
}