#include <iostream>
#include <cmath>

using namespace std;

typedef long long ll;

int main()
{
    int t;

    cin >> t;

    for(int i = 0; i < t; i++)
    {
        ll A, B;

        cin >> A >> B;

        if(B % 2 == 1)
        {
            cout << -1 << endl;
            continue;
        }

        bool jelIzasaoIkad = false;

        for(ll i = 1; i <= sqrt(A); i+=(ll)2)
        {
            if(A % i == 0)
            {
                ll drugiDeljenik = A / i;

                if((i ^ drugiDeljenik) == B)
                {
                    cout << i << " " << drugiDeljenik << endl;
                    jelIzasaoIkad = !jelIzasaoIkad;
                }
            }
        }
            if(jelIzasaoIkad == false)
            {
                cout << -1 << endl;
            }
    }



    return 0;
}