#include<iostream>
using namespace std;

unsigned long long T, A[10000], B[10000], X[10000], Y[10000], xr, pom;
int i, j; 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];
		Y[i]=-1;
		j=1;
		while (j*j<=A[i]) {
			if (A[i]%j == 0) {
				X[i] = j;
				pom = X[i]^B[i];
				if (A[i] == pom*X[i]) Y[i]=pom;
			}
			j += 2;
		}
	}
	
	for (i=0; i<T; i++) {
		if (Y[i]==-1) cout << "-1" << endl;
		else cout << X[i] << " " << Y[i] << endl;
	}
}