#include <iostream>
#include <cmath>
using namespace std;

pair <long long,long long> a[10000];

int main()
{
    int T;
    cin >> T;
    for (int i = 0; i < T; i++)
        cin >> a[i].first >> a[i].second;
    for (int i = 0; i < T; i++) {
        bool p = false;
        for (int j = 1; j <= sqrt(a[i].first); j++) {
            if (a[i].first % j == 0) {
                long long x = j;
                long long y = a[i].first / j;
                if (a[i].second == (x ^ y)) {
                    p = true;
                    cout << x << " " << y << endl;
                    break;
                }
            }
        }
        if (!p)
            cout << "-1" << endl;
    }
    return 0;
}