#include <iostream>
//^
using namespace std;

long long a[10000], b[10000];

int main()
{
    int T;
    cin >> T;
    for(int i = 0; i < T; i++)
    {
        long long a, b, p =-1, k = -1;
        cin >> a >>b;
        while(k<(a+1)/2 && p!=b)
        {
            k+=2;
            if(a%k == 0)
            {
                p = k^(a/k);
            }

        }
        if(p!=b)
            cout << -1;
        else
            cout << k << " " << a/k << endl;
    }
}