#include <iostream>
#include <math.h>

using namespace std;

void nadjiXY(int X[], int Y[], int A, int B, int br){
    if (B % 2 == 1){
        X[br] = -1;
        Y[br] = -1;
        return;
    }

    int x, y;
    int x_xor_y;

    for (int i = 1; i <= sqrt(A); i += 2){
        if (A % i != 0)
            continue;
        x = i; y = A / i;
        x_xor_y = x^y;
        if (x_xor_y == B){
            X[br] = x;
            Y[br] = y;
            return;
        }
    }

    X[br] = -1;
    Y[br] = -1;
}

int main()
{
    int T;
    cin >> T;
    int A, B;
    int X[T], Y[T];
    for (int i = 0; i < T; ++i){
        cin >> A >> B;
        nadjiXY(X, Y, A, B, i);
    }

    for (int i = 0; i < T; ++i){
        if (X[i] == -1){
            cout << -1;
        } else {
            cout << X[i] << " " << Y[i] << endl;
        }
    }

    return 0;
}