#include <iostream>
#include <stdio.h>
#include <stdlib.h>

using namespace std;

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