#include<bits/stdc++.h>
using namespace std;
unsigned long long t,x,y,a[10006],b[10006],i,j,n;
main()
{
	cin>>t;
	for(i=1;i<=t;i++)
	cin>>a[i]>>b[i];
	
	for(i=1;i<=t;i++)
	{
	for(j=3;j*j<=a[i];j+=2)
	if(a[i]%j==0)
	{
		if(j xor (a[i]/j) ==b[i])
		{
			cout<<j<<" "<<a[i]/j<<endl;
			j=a[i]+3;
		}
	}
	
	if(j<a[i])
	cout<<-1<<endl;	
	}
	
	return 0;
}