#include <bits/stdc++.h>
using namespace std;
int ucitaj()
{
	
	unsigned int rez=0;
	char ch;
	while (true)
	{
		ch=getchar();
		if (ch<'0' or ch>'9') break;
		rez=rez*10+(ch-'0');
	}
	return rez;
}
int main()
{
	unsigned int T;
	T=ucitaj();
	unsigned int A[T+1][3],p,i,j,n,pom;
	for (i=0;i<T;i++)
	{
		for (j=0;j<2;j++)
		{
			A[i][j]=ucitaj();
		}
	}
	for (j=0;j<T;j++)
	{
		pom=0;
		p=1;
		n=A[j][0];
	for (i=2;i<=n/i;i++)
	{
		while (n%i==0)
		{
			n=n/i;
			//cout<<"Factor:"<<i<<endl;
			p=p*i;
			//cout<<p<<endl;
			//system("pause");
			if ((p^A[j][0]/p)==A[j][1])
			{
				
				printf("%u ",p);
				printf("%u\n",A[j][0]/p);
				goto sledeci;
				pom=1;
			}
		}
	}
	if(n>1)
	{
		//cout<<"Factor:"<<n<<endl;
		p=p*n;
		if ((p^A[j][0]/p)==A[j][1])
		{
			printf("%u ",p);
			printf("%u\n",A[j][0]/p);
			pom=1;
		}
	}
	if (pom==0)
	{
		printf("-1\n");
	}
	sledeci:
		n=0;
	}
}