#include <bits/stdc++.h>
using namespace std;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;

	long long a, b, x, y;
	while (n){
		cin >> a >> b;
		x = -1, y = -1;
		for (int i = 2; i <= sqrt(a); i++){
			if (a % i == 0) {
				x = i;
				y = a / i;
				if ((x^y) == b){
					cout << x << " " << y << endl;
					continue;
				}
			}
		}
		if (x == -1)
			cout << -1 << endl;
		n--;
	}

	return 0;
}