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

namespace petlja
{
	class Program
	{
		static void Main(string[] args)
		{
			int t = int.Parse(Console.ReadLine());
			string[] unos;
			double x, y;
			ulong z = 0;
			ulong[] a = new ulong[t], b = new ulong[t], a1 = new ulong[t], b1 = new ulong[t];
			for (int i = 0; i < t; i++)
			{
				unos = Console.ReadLine().Split(' ');
				a[i] = Convert.ToUInt64(unos[0]);
				b[i] = Convert.ToUInt64(unos[1]);			
			}
			for (int i = 0; i < t; i++)
			{
				for (ulong j = 0; j <= Math.Sqrt(a[i]); j++)
				{
					x = Math.Sqrt(a[i] + j * j);
					y = (a[i] - 1) / Math.Pow(2, j);					
					if (x == (ulong)x)
					{
						a1[i] = (ulong)x - j;
						b1[i] = (ulong)x + j;
						if ((a1[i] ^ b1[i]) == b[i])
						{
							Console.WriteLine(a1[i] + " " + b1[i]);
							break;
						}
						else
						{
							if (j > 10000000)
							{
								Console.WriteLine("-1");
								break;
							}
						}
					}
					if (j != 0)
					{
						if (y == (ulong)y)
						{
							if (j == 1)
							{
								z = (ulong)Math.Pow(2, y) % a[i];
								if (z == 1 || z == a[i] - 1)
								{
									Console.WriteLine("-1");
									break;
								}
							}
							else
							{
								z = (ulong)Math.Pow(z, 2) % a[i];
								if (z == a[i] - 1)
								{
									Console.WriteLine("-1");
									break;
								}
							}
						}
					}
				}
			}
		}
	}
}