#include <iostream>

using namespace std;

int main()
{
    int t;
    cin >> t;
    for(int i = 0;i<t;i++)
    {
        long long int a;
        long long int b;
        cin >> a;
        cin >> b;
        if(b%2!=0)
        {
            cout << -1 << endl;
            break;
        }

        int provera = 0;
        long long int d = 3;
        while(d*d<=a && provera==0)
        {
            if(a%d==0)
                if(((a/d)^d)==b )
                {
                    provera = 1;
                    cout << d << " " << a/d << endl;
                    break;
                }
                d+=2;
        }
        if(provera==0)cout << -1 << endl;
    }
    return 0;
}