#include <iomanip>
#include <math.h>
#include <iostream>
#include <sstream>
using namespace std;
int main()
{
	int t, a, b, x, y, delilac, broj, k;
	bool nasao = false;
	int bin1[64];
	int bin2[64];
	int bin3[64];
	int niz[1000];
	cin >> t;
	for (int i = 0; i < t * 2; i+=2)
	{
		cin >> niz[i];
		cin >> niz[i + 1];
	}

	for (int i = 0; i < t * 2; i+= 2)
	{
		a = niz[i];
		b = niz[i + 1];
		if (a < 10000 && b < 10000)
		{
			k = 63;
			for (int j = 0; j < 64; j++)
			{
				bin3[j] = 0;
			}
			while (b > 0)
			{
				bin3[k] = b % 2;
				b /= 2;
				k--;
			}
			delilac = 1;
			while (delilac < a / 2)
			{
				x = 0;
				y = 0;
				nasao = false;
				if (a % delilac == 0)
				{
					x = delilac;
					y = a / delilac;
					broj = 0;
					k = 63;
					for (int j = 0; j < 64; j++)
					{
						bin1[j] = 0;
					}
					while (x > 0)
					{
						bin1[k] = x % 2;
						x /= 2;
						k--;
					}
					k = 63;
					for (int j = 0; j < 64; j++)
					{
						bin2[j] = 0;
					}
					while (y > 0)
					{
						bin2[k] = y % 2;
						y /= 2;
						k--;
					}
					for (int i = 0; i < 64; i++)
					{

						if ((bin1[i] ^ bin2[i]) == bin3[i])
						{
							broj++;
						}
					}
					x = delilac;
					y = a / delilac;
					if (broj == 64)
					{
						cout << x << " " << y << endl;
						nasao = true;
						break;
					}
				}
				delilac++;
			}
			if (!nasao)
			{
				cout << -1 << endl;
			}
		}
		else
		{
			cout << -1 << endl;
		}
	}
}