#include "iostream"
using namespace std;
int bitx[63];
struct par {
	int a; int b; int x; int y;
};
void nu(int x, int y) {
	x = 0; y = 0;
}
int main(){
	int n; par* p; cin >> n; p = new par[n];
	for (int i = 0; i < n; i++) { cin >> p[i].a >> p[i].b; }
	for (int i = 0; i <n ; i++) {
		nu(p[i].x, p[i].y);
		for (int j = 0; j < p[i].a; j++) {
			if (p[i].a % j == 0) {
				p[i].x = j; p[i].y = p[i].a / j;
				if ((p[i].x ^ p[i].y) == p[i].b)break;
				else nu(p[i].x, p[i].y);
			}
		}
		if (p[i].x == -1 || p[i].y == -1) {
			cout << -1;
		}
		else { cout << p[i].x << ' ' << p[i].y; }
	}
	return 0;
}