using System;

namespace Zadatak5_kv
{
    class Program
    {
        static void Main(string[] args)
        {
            int t = Convert.ToInt32(Console.ReadLine());
            long[] x = new long[t];
            long[] y = new long[t];
            long[] a=new long [t];
            long[] b=new long [t];
            for(int i = 0; i < t; i++)
            {
                string s = Console.ReadLine();
                string[] s1 = s.Split(' ');
                a[i] = Convert.ToInt64(s1[0]);
                b[i] = Convert.ToInt64(s1[1]);
            }
            for(int i = 0; i < t; i++)
            {
                int c = 0;
                long j = Convert.ToInt64(Math.Sqrt(a[i]));
                while (c == 0 && j >= 1)
                {
                    if (a[i] % j == 0)
                    {
                        long p = a[i] / j;
                        if (b[i] == Convert.ToInt64(j ^ p))
                        {
                           x[i] = j;
                           y[i] = p;
                           c++;
                        }
                    }
                    j--;
                }
                if (x[i] != 0 && y[i] != 0)
                {
                    Console.WriteLine("{0} {1}", x[i], y[i]);
                }
                else
                {
                    Console.WriteLine(-1);
                }
            }
        }
    }
}