#include <stdio.h>
#include <math.h>
main() {
	int i, j, flag;
	int T;
	long long A[10000], c;
	long long B[10000];
	long long X[10000], Y[10000];
	
	scanf("%d", &T);
	for (i=0; i<T; i++){
		scanf("%lld %lld", &A[i], &B[i]);
		}
	for (i=0; i<T; i++){
		j=1;
		flag = 0;
		c=ceil(A[i]/2);
		while(j<c){
			if (A[i]%j==0){
				Y[i]=A[i]/j;
				X[i]=j;
				if ((X[i]^Y[i])==B[i]){
					printf("%lld %lld\n", X[i], Y[i]);
					flag =1;
					break;
				}
			}
		j=j+1;	
		}
		if (flag == 0){
			printf("%d\n", -1);
		}
	}
}