#include<iostream>
#include<vector>
#include<string>

using namespace std;

string Solve(long long Ai, long long Bi) {
	vector<long long> Solutions;
	vector<long long> prevSolutions;
	Solutions.push_back(0L);
	long tests = 0;
	for (long long bit = 1; (Ai / bit) >= bit; bit <<= 1)
	{
		tests += Solutions.size();
		{
			vector<long long> copy = prevSolutions;
			prevSolutions = Solutions;
			Solutions = copy;
		}
		const long long mk = bit | (bit - 1);
		Solutions.clear();
		for (long long px : prevSolutions)
		{
			long long prevy = (px ^ Bi) & mk;
			if ((((px * prevy) ^ Ai) & mk) == 0)
			{
				Solutions.push_back(px);
			}
			long long x = px | bit;
			long long y = (x ^ Bi) & mk;
			if ((((x * y) ^ Ai) & mk) == 0)
			{
				Solutions.push_back(x);
			}
		}
	}
	tests += Solutions.size();
	{
		vector<long long> copyvec = prevSolutions;
		prevSolutions = Solutions;
		Solutions = copyvec;
	}
	Solutions.clear();
	for (long long tx : prevSolutions)
	{
		if (Ai / tx >= tx)
		{
			long long ty = Bi ^ tx;
			if (tx * ty == Ai)
			{
				Solutions.push_back(tx);
			}
		}
	}
	
	if (!Solutions.empty()) {
		string x = to_string(Solutions[0]);
		x += " " + to_string(Ai / Solutions[0]);
		return x;
	}
	else {

		string x = to_string(-1);
		return x;
	}

}


int main() {

	long long n, Ai, Bi, Xi, Yi;
	vector<string> Solutions;
	std::cin >> n;
	for (int i = 0; i < n; i++) {

		std::cin >> Ai >> Bi;
		
		Solutions.push_back(Solve(Ai, Bi));
	}
	for (int i = 0; i < n; i++) {
		cout << Solutions[i] << endl;
	}
	
	return 0;
}