#include <iostream>
#include <math.h>
//^
using namespace std;

long long a[10000], b[10000];

void resiZadatak(long long a, long long b)
{
   long long i = -1;
   long long p = -1;
   while (i<=sqrt(a) && p!=b)
    {
        i+=2;
        if (a%i == 0)
        {
            p = i^(a/i);
        }

    }
    if(p!=b)
        cout << -1;
    else
        cout << i <<" "<< a/i << endl;
}

int main()
{
    int T;
    cin >> T;
    for(int i = 0; i < T; i++)
    {
        cin >> a[i] >> b[i];
        resiZadatak(a[i], b[i]);
    }
}