#include <iostream>
using namespace std;

int main()
{
	int T;
	long long int M, X;
	int i,k,  kraj;
	long long int a, b;
	long long int myxorab = 0;
	bool found = false;
	long int ra[10000];
	long int rb[10000];

	cin >> T;

	for (k = 0; k < T; k++) {

		cin >> M >> X;
		i = 1;
		kraj = 0;
		found = false;

		while ((i <= sqrt(M)) && (kraj == 0)) {
			a = i;
			b = M / a;

			if (b * a == M) {
				//myxorab = myXOR(a, b);
				myxorab = a ^ b;
			
				if (myxorab == X) {
					ra[k] = a;
					rb[k] = b;
					//out << a << ' ' << b << endl;
					kraj = 1;
					found = true;
				}
			}
			i = i + 2;
		}

		if (!found)
		{
			ra[k] = -1;
			rb[k] = -1;
		}
	}// T

	for (k = 0; k < T; k++) {
		if (ra[k] == -1) {
			cout << ra[k] << endl;
		}
		else
			cout << ra[k] << ' ' << rb[k] << endl;
	}

	return 0;
}