#include <bits/stdc++.h>

using namespace std;

int main ()
{
	int t;
	cin >> t;
	while(t--)
	{
		long long a, b;
		cin >> a >> b;
		bool found = false;
		for(long long i=1;i<=sqrt(a);i+=2)
		{
			if(a%i == 0)
			{
				if((i^(a/i)) == b)
				{
					cout << i << " " << a/i << endl;
					found = true;
					break;
				}
			}
		}
		if(!found)
		{
			cout << -1 << endl;
		}
	}
}