using System;


namespace Zadatak4
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());

            long[,] a = new long[n, 2];
            for (int i = 0; i < n; i++)
            {
                string[] str = Console.ReadLine().Split();
                a[i, 0] = long.Parse(str[0]);
                a[i, 1] = long.Parse(str[1]);
            }
            for (int i = 0; i < n; i++)
            {

                long r = (long)Math.Sqrt(a[i, 0]);
                if ((r ^ r) == a[i, 1]) Console.WriteLine(r + " " + r);
                else
                {

                    long pr = 1;
                    bool t = true;
                    long broj = r;
                    if (broj % 2 == 0)
                    broj+=1;
                    while (pr < r && broj < a[i, 0] / 2)

                    {
                        if (((a[i, 0] / pr) ^ pr) == a[i, 1])
                        {

                            Console.WriteLine(pr + " " + a[i, 0] / pr);
                            t = false;
                            break;

                        }
                        else if (((a[i, 0] / broj) ^ broj) == a[i, 1])
                        {

                            Console.WriteLine(broj + " " + a[i, 0] / broj);
                            t = false;
                            break;

                        }
                        pr += 2;
                        broj += 2;
                    }
                    if (t) Console.WriteLine(-1);
                }
            }
        }
    }
}