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

namespace ConsoleApplication29
{
    class Program
    {
        static void Main(string[] args)
        {
            int t, k=0;
            ulong a, b, y;
            string[] s;
            t = int.Parse(Console.ReadLine());
            ulong[] niza = new ulong[t + 1];
            ulong[] nizb = new ulong[t + 1];
            for (int i = 1; i <= t; i++)
            {
                s = Console.ReadLine().Split();
                a = ulong.Parse(s[0]);
                niza[i] = a;
                b = ulong.Parse(s[1]);
                nizb[i]=b;
            }
                for (int i = 1; i <= t; i++)
                {
                    for (ulong j = 1; j <= (ulong)Math.Sqrt(niza[i]); j++)
                    {
                        k = 0;
                        if (niza[i] % j == 0)
                        {
                            y = niza[i] / j;
                            if ((ulong)(j ^ y) == nizb[i])
                            {
                                Console.WriteLine(j + " " + y);
                                k++;
                                break;
                            }
                        }
                    }
                        if (k == 0)
                            Console.WriteLine(-1);
                }
        }
    }
}