#include <iostream>
#define ll long long
using namespace std;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int t;
	ll a, b;
	cin >> t;
	bool p;
	for(int i = 0; i < t; i++)
	{
		cin >> a >> b;
		if(b % 2) cout << -1 << "\n";
		else
		{
			p = 0;
			for(ll i = 1; i * i <= a && !p; i += 2)
				if(a % i == 0)
					if((i ^ (a / i)) == b)
					{
						cout << i << " " << a / i << "\n";
						p = 1;
					}
			if(!p) cout << -1 << "\n";
		}
	}
}