#include <stdio.h>
#include <iostream>
#include <math.h>

using namespace std;
//int a, b;
//cin >> a >> b;
//printf("%d", a ^ b);

int main()
{
	
	unsigned long long A,B;
	
	int t;

	cin >> t;
	
	for (int j = 0; j < t; j++) 
	{
		cin >> A >> B;
		int a = 1;
		
		for (int i = 3; i <= sqrt(A); i++)
		{
			if (A % i == 0)
			{
				unsigned long long c = A / i;
				if ((c ^ i) == B) {
					cout << c << ' ' << i;
					a = 0;
					break;
				}

			}
			if (a == 0) cout << -1;
		}
		
	}
}