#include <iostream>

using namespace std;
long long int typedef ll;

int main()
{
	bool nadjen;
	ll a, b, x; int n; cin >> n;
	for (int i = 0; i < n; i++)
	{
		x = -1;
		nadjen = false;
		cin >> a >> b;
		if (b % 2 == 0)
		{
			while (x*x <= a && !nadjen)
			{
				x += 2;
				if (a%x == 0 && ((x) ^ (a / x)) == b) nadjen = true;
			}
		}
		if (nadjen) cout << a/x << " " << x <<endl;
		else cout << -1<<endl;
	}
	return 0;
}