#include <bits/stdc++.h>

using namespace std;
void f(long long a, long long b)
{
   long long x, i, sq = sqrt(a);
        for(i = 3; i <= sq + 2; i = i + 2)
        if(a%i == 0)
        {
            x = a/i;
            if((x^i) == b)
            {
                cout << x << " " << i << endl;
                return;
            }
        }
    cout << -1 << endl;
}
int main()
{
    long long t, a, b;
    ios_base::sync_with_stdio(false);
    cin >> t;
    while(t)
    {
        cin >> a >> b;
        f(a, b);
        t--;
    }
    return 0;
}