using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp1
{
	class Program
	{
		static void Main(string[] args)
		{
			int t = int.Parse(Console.ReadLine());
			string[] izlaz = new string[t];

			for (int i = 0; i < t; i++)
			{
				bool nasao = false;

				string[] unos = Console.ReadLine().Split();
				long a = long.Parse(unos[0]);
				long b = long.Parse(unos[1]);

				for (int x = 1; x <= Math.Sqrt(a); x++)
				{
					if(a % x == 0 && (x^(a/x)) == b)
					{
						izlaz[i] = x + " " + a / x;
						nasao = true;
					}
				}
				if(!nasao)
					izlaz[i] = "-1";
			}
			foreach(string str in izlaz)
			{
				Console.WriteLine(str);
			}

		}
	}
}