#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
	int t;
	scanf("%i",&t);
	while(t--)
	{
		ll a,b;
		scanf("%lld %lld",&a,&b);
		ll f=-1,s=-1;
		for(ll x=1;x*x<=a;x++) if(a%x==0)
		{
			ll y=a/x;
			if((x^y)==b){ f=x,s=y;break;}
		}
		if(f==-1) printf("-1\n");
		else printf("%lld %lld\n",f,s);
	}
	return 0;
}