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

unsigned long long faktor( unsigned long long x)
{
   unsigned long long up = 1+sqrt(x);
   unsigned long long i=0, k=0, min=x;

   for(i=3; i<=up; i+=2)
   {
      if( x%i == 0)
      {
         k++;
         if(min > i)
         {
           min=i;
         }
      }
   }
   if(k==0)
    {
    	min=1;
	}
   return min;
}

int main()
{
	unsigned short T=0;
	cin >> T;
	unsigned long long A [T],B [T],C [T];
	for(int i=0;i<T;i++)
	{
		cin >> A[i] >> B[i];
		unsigned long long up = 1+sqrt(A[i]);
	}
	for(int k=0;k<T;k++)
	{
		C[k]=faktor(A[k]);
		//cout << "C[" << k << "] = " << C[k] << endl;
	}
	for(int m=0;m<T;m++)
	{
		if(A[m]==(C[m]*(A[m]/C[m])) && B[m]==(C[m]^(A[m]/C[m])))
		{
			B[m]=A[m]/C[m];
			A[m]=C[m];
		}
		else
		{
			A[m]=0;
			B[m]=0;
		}
	}
	cout << "" << endl;
	cout << "==========================" << endl;
	cout << "" << endl;
	for(int n=0;n<T;n++)
	{
		if(A[n]==0 && B[n]==0)
		{
			cout <<"-1"<< endl;
		}
		else
		{
			cout<< A[n] << " " << B[n] << endl;
		}
	}
}