#include <bits/stdc++.h>

using namespace std;

void solution(unsigned long long a, unsigned long long b)
{
    bool postoji = false;
    for (unsigned long long i = 1; i*i <= a; i+=2) {
        if (a % i == 0)
        {
            if ((i ^ a/i) == b)
            {
                cout << i << " " << a/i << "\n";
                postoji = true;
                break;
            }
        }
    }
    if (!postoji)
        cout << -1 << "\n";
}

int main()
{
    int t;
    cin >> t;
    unsigned long long a, b;
    while (t--) {
        cin >> a >> b;
        solution(a, b);
    }
    return 0;
}