#include <iostream>
#define MAX_N 10000

using namespace std;

long long A[MAX_N], B[MAX_N], Ar[MAX_N] = { -1 }, Br[MAX_N] = {-1}, R[MAX_N] = { 0 };



int main() {
	int T,i;
	cin >> T;
	for (i = 0; i < T; i++) {
		cin >> A[i] >> B[i];
		if (B[i] % 2 != 0) R[i] = -1;
		else if (B[i] !=0 && int(sqrt(A[i])) * int(sqrt(A[i])) == A[i]) R[i] = -1;
		else if (B[i] == 0 && int(sqrt(A[i])) * int(sqrt(A[i])) == A[i]) {
			Ar[i] = int(sqrt(A[i]));
			Br[i] = int(sqrt(A[i]));
		}
		else {
			for (long long j = long long(sqrt(A[i])); j <= A[i]; j++) {
				if (A[i] % j == 0) if ((j ^ (A[i] / j)) == B[i]) {
					Ar[i] = j;
					Br[i] = A[i] / j;
				}
			}
		}
	}
	for (i = 0; i < T; i++) {
		if (R[i] == -1 || A[i]==-1) cout << -1 << endl;
		else cout << Ar[i] << " " << Br[i] << endl;
	}
}