#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
using namespace std;

int main(int argc, char** argv) {
	long a,b;
	unsigned x,y;
	int t,i;
	cin>>t;
	for (i=0;i<t;i++)
	{
		cin>>a;
		cin>>b;
		for(x=1;x<=sqrt(a);x++)
		{
			for(y=1;y<=sqrt(a);y++)
			{
				if (x*y==a && (x^y)==b)
				{
					break;
				}
			}
		if (x*y==a && x^y==b)
			{
				cout<<x<<" "<<y<<endl;
				break;
			}
		}
		if (x*y!=a || (x^y)!=b)
		{
		cout<<"-1"<<endl;
		}	
	}	
	return 0;
}