#include <iostream>
#include <vector>
#include <cmath>
using namespace std;

bool isPerfectSquare(long long x)
{
	long double sr = sqrt(x);
	return ((sr - floor(sr)) == 0);
}

int main()
{
	long long t = 0;
	cin >> t;
	vector< vector<long long> > pairs(t);
	for (int i = 0; i < t; i++)
	{
		long long a, b;
		cin >> a >> b;
		pairs[i].push_back(a);
		pairs[i].push_back(b);
	}
	for (int i = 0; i < t; i++)
	{
		long long a = pairs[i][0];
		long long b = pairs[i][1];
		if (b % 2 == 1)
		{
			cout << -1 << endl;
		}
		else if (b == 0)
		{
			if (isPerfectSquare(a) == true)
				cout << sqrt(a) << " " << sqrt(a) << endl;
			else
			{
				cout << -1;
			}
		}
		else
		{
			bool z = false;
			for (int j = 1; j < a / 2; j = j + 2)
			{
				if (a%j == 0 && ((a / j) ^ j) == b)
				{
					cout << j << " " << a / j << endl;
					z = true;
					break;
				}
			}
			if (z == false)
				cout << -1 << endl;
		}
	}
}