#include<stdio.h>
#include<limits.h>
using namespace std;

long long a1,b1,a1pom;
int a[25],b[25],t,i,bra=1,brb=1,x[25],y[25],moze=0;

long long xpr,ypr;

void stampaj()
{
	if (i==t) printf("%lld %lld",xpr,ypr);
	if (i<t) printf("%lld %lld\n",xpr,ypr);
}

void nene()
{
	if (i==t) printf("-1"); else printf("-1\n");
}



int provera()
{
	long long tt=1;
	xpr=0; ypr=0;
	
	for (int m=1;m<=brb;m++)
	{
		xpr=xpr+x[m]*tt;
		ypr=ypr+y[m]*tt;
		tt=tt*2;
	}
	
	while(1==1)
	{
		if (xpr*ypr==a1pom) return 1;
		if ((xpr+tt)*(ypr+tt)>a1pom) break;
		if ((xpr+tt)*(ypr+tt)==a1pom) {xpr=xpr+tt; ypr=ypr+tt; return 1;}
		xpr=xpr+tt; ypr=ypr+tt;
		if (tt*2>LLONG_MAX) break; else tt=tt*2;
	}
	
	return 0;
}

int pravi(int t,int raspored)
{
	int pom=0;
	if (t==brb+1) return provera();
	if (raspored==1) {x[t]=1; y[t]=0; pom=pravi(t+1,b[t+1]);}
	if (pom==1) return 1;
	if (raspored==1) {x[t]=0; y[t]=1; pom=pravi(t+1,b[t+1]);}
	if (pom==1) return 1;
	if (raspored==0) {x[t]=1; y[t]=1; pom=pravi(t+1,b[t+1]);}
	if (pom==1) return 1;
	if (raspored==0) {x[t]=0; y[t]=0; pom=pravi(t+1,b[t+1]);}
	if (pom==1) return 1;
	return 0;
}

int main()
{
	scanf("%d",&t);
	
	for (i=1;i<=t;i++)
	{
		scanf("%lld%lld",&a1,&b1);
		a1pom=a1;
		bra=1; brb=1;
		while(1==1)
		{
			a[bra]=a1%2;
			a1=a1/2;
			if (a1==0) break;
			bra++;
		}
		while(1==1)
		{
			b[brb]=b1%2;
			b1=b1/2;
			if (b1==0) break;
			brb++;
		}
		
		if (b[1]==1) {nene(); continue;}
		x[1]=1;
		y[1]=1;
		if (a1pom==1) {xpr=1; ypr=1; stampaj();}
		int moze=pravi(2,b[2]);
		if (moze==0) {nene(); continue;}
		stampaj();
	}
}