#include <iostream>
#include <cmath>
#define ll long long

using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int t;
    cin >> t;
    while (t--){
        ll a, b;
        cin >> a >> b;
        if (b % 2){
            cout << -1 << endl;
            continue;
        }
        int gr = sqrt(a);
        bool nasao = false;
        for (int i = 1; i <= gr; i += 2){
            if (a % i == 0 && (i^(a/i)) == b){
                cout << i << " " << a/i << endl;
                nasao = true;
                break;
            }
        }
        if (!nasao)
            cout << "-1" << endl;
    }
    return 0;
}