#include <stdio.h>
#include <math.h>

int main() {

	int t;
	unsigned long a, b, x, y;
	scanf(" %d", &t);
	for(int i = 1; i <= t; i++) {
		scanf(" %ld %ld", &a, &b);
		int nadjen = 0;
		for(x = 1; x <= sqrt(a); x+=2) {
			if(a % x == 0) {
				y = a / x;
				if(b == (x ^ y)) {
					nadjen = 1;
					break;
				}
			}
		}

		if(nadjen)
			printf("%ld %ld\n", x, y);
		else
			printf("-1\n");
	}

	return 0;
}