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

int main()
{
    short t;
    cin >> t;
    long long a, b;
    unsigned x[t], y[t];
    for(short i = 0; i < t; i++) {
        cin >> a >> b;
        x[i] = floor(sqrt(a));
        while(x[i]) {
            if(a % x[i]) {
                x[i]--;
                continue;
            }
            y[i] = a / x[i];
            if((x[i] ^ y[i]) == b) {
                break;
            }
            x[i]--;
        }
        if(!x[i]) x[i] = -1;
    }
    for(short i = 0; i < t; i++) {
        if(x[i] == -1)
            cout << -1 << endl;
        else
            cout << x[i] << " " << y[i] << endl;
    }
    return 0;
}