// Example program
#include <iostream>
#include <cmath>

using namespace std;

int main()
{
    int n;
    cin >> n;
    int* n1 = new int[n];
    int* n2 = new int[n];
    int br = 0;
    int flag = 0;
    for (int i = 0; i < n; i++)
    {
     long long a,b;
     cin >> a;
     cin >> b;
     for (int i = 3; i <= sqrt(a); i+=2)
     {
         if (a%i==0)
         {
          if (i^(a/i) == b)
          {
             flag = 1;
             n1[br] = i;
             n2[br] = a/i;
             br++;
             break;
          }
         }
     }
     if (flag == 0)
     {
         n1[br++] = -1;
     }
    }
    for (int i = 0; i < n; i++)
    {
        if (n1[i] == -1) 
        {
            cout << -1 << endl;
            continue;
        }
        cout << n1[i] << " " << n2[i] << endl;
        
    }
}