#include <bits/stdc++.h>

using namespace std;

int main ()
{
	ios_base::sync_with_stdio(false);
	int t;
	cin >> t;
	while(t--)
	{
		long long a, b;
		cin >> a >> b;
		bool found = false;
		for(long long i=1;i*i<=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;
		}
	}
}