#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<algorithm>
#include<math.h>
#define A 100000001
using namespace std;
bool bin1[A],bin2[A],bin3[A];
long long res1[10000],res2[10000];
int main()
{
	unsigned long long a,b,xx=0;
	int T;
	int solved=0;
	scanf("%d",&T);
	for(int i=1;i<=T;i++)
	{
		scanf("%lld%lld",&a,&b);
		long long k=0,m=sqrt(a)+1;
		while(m*m>=1)
		{
			if(a%m==0)
			{
				unsigned long long x,y,x1,y1;;
				x=m;
				y=a/m;
				x1=x;
				y1=y;
				long i1=0,i2=0;
				while(x>0)
				{
					bin1[i1]=x%2;
					x=x/2;
					i1++;
				}
				while(y>0)
				{
					bin2[i2]=y%2;
					y=y/2;
					i2++;
				}
				long i3;
				if(i1>i2)
				{
					for(i2;i2<i1;i2++)
					{
						bin2[i2]=0;
					}
				}
				else if(i1<i2){
					for(i1;i1<i2;i1++)
					{
						bin1[i1]=0;
					}
				}
				for(i3=0;i3<i1;i3++)
				{
					if(bin1[i3]==bin2[i3])
					bin3[i3]=0;
					else bin3[i3]=1;
				}
				long long vr1=0;
				for(int i4=i3-1;i4>=0;i4--)
				{
					vr1=vr1*2+bin3[i4];
				}
				if(vr1==b)
				{
					res1[xx]=x1;
					res2[xx]=y1;
					solved=1;
					xx++;
				}
			}
			if(solved==0)
			m--;
			else m=0;
		}
		if(solved==0)
		{
			res1[xx]=-1;
			xx++;
		}
		else solved=0;
	}
	for(int iii=0;iii<xx;iii++)
	{
		if(res1[iii]!=-1)
		printf("%d %d\n",res1[iii],res2[iii]);
		else printf("-1\n");
	}
}