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

int main(){
	int a,b,c,i,f,x,y,j,t;
	float d;
	scanf("%d", &t);
	for (j = 1 ; j <= t ; j++)
		{
		scanf("%d %d", &a, &b);
		c = floor(sqrt(a));
		x = 0;
		for (i = 1; i <= c ; i++)
			{
			d = a/i;
			f = floor(d);
			if (f != d) continue;
			if ((i ^ f) != b) continue;
			else{
				x = i;
				y = f;
				printf("%d %d\n", x, y);
				}
			} 
		if (x == 0) printf("-1\n");
		}
	}