#include<iostream>
using namespace std;

unsigned long long T, A[10000], B[10000], X, Y, xr;
int i; bool ind;

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);

	
	cin >> T;
	for (i=0; i<T; i++)
		cin >> A[i] >> B[i];
	
	for (int j=0; j<T; j++) {
		i = 1; ind = true;
		while (i*i<=A[j]) {
			if (A[j]%i==0) {
				X = i;
				Y = A[j]/i;
				xr = X^Y;
				if (xr == B[j]) {
					cout << X << " " << Y << endl;
					ind = false;
				} 
			}
			i++;
		}
		if (ind) cout << -1 << endl;
	}
}