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

namespace Zadatak_5
{
    class Program
    {
        static void Main(string[] args)
        {
            int t = int.Parse(Console.ReadLine());
            long[] a = new long[t];
            long[] b = new long[t];
            for(int i = 0; i < t; i++)
            {
                string pom = Console.ReadLine();
                string[] pom1 = pom.Split(' ');
                a[i] = Convert.ToInt64(pom1[0]);
                b[i] = Convert.ToInt64(pom1[1]);
            }
            for (int j = 0; j < t; j++)
            {
                Delioci(a[j], b[j]);
            }

        }
        static bool Delioci(long n,long m)
        {
            for (long i = 1; i <= Math.Sqrt(n); i += 2)
            {
                if (n % i == 0)
                {
                    if ((i ^ n/i) == m)
                    {
                        Console.WriteLine("{0} {1}", i, n / i);
                        return true;
                    }
                }
            }
            Console.WriteLine("-1");
            return false;
        }
    }
}