import java.util.ArrayList;
import java.util.Scanner;

public class Luxor {

	public static ArrayList<Long> delioci2(long A) {
		// long []niz=new long[A];
		ArrayList<Long> lista = new ArrayList<Long>();

		for (long i = 1; i <= Math.sqrt(A); i++) {
			if (A % i == 0) {
				if (A / i == i) {
					lista.add(i);
				} else {
					lista.add(i);
					lista.add(A / i);
				}
			}

		}

		return lista;
	}

	public static void main(String[] args) {
		// TODO Auto-generated method stub

		Scanner scan = new Scanner(System.in);
		int T = scan.nextInt();
		long[][] matrica = new long[T][2];
		for (int i = 0; i < T; i++) {
			matrica[i][0] = scan.nextLong();
			matrica[i][1] = scan.nextLong();
		}
		for (int j = 0; j < T; j++) {
			ArrayList<Long> lista = delioci2(matrica[j][0]);

			long a = 0;
			long b = 0;
			for (int q = 0; q < lista.size(); q++) {

				long h = (long) (lista.get(q)) ^ (long) ((matrica[j][0]) / (long) (lista.get(q)));

				if (matrica[j][1] == h) {
					a = lista.get(q);

					b = (long) (matrica[j][0] / lista.get(q));

					break;
				}

			}

			if (a == 0 && b == 0) {
				System.out.println(-1);
			} else {
				System.out.println(a + " " + b);
			}
		}
	}
}