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

namespace Luxor
{
    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
                {
                    bool l = true;
                    long p = 1;
                    long w = r;
                    if (w % 2 == 0) w++;
                    while (p < r && w < a[i, 0] / 2)
                    {
                        if (((a[i, 0] / p) ^ p) == a[i, 1])
                        {
                            Console.WriteLine(p + " " + a[i, 0] / p);
                            l = false;
                            break;

                        }
                        else if (((a[i, 0] / w) ^ w) == a[i, 1])
                        {
                            Console.WriteLine(w + " " + a[i, 0] / w);
                            l = false;
                            break;
                        }
                        p += 2;
                        w += 2;
                    }
                    if (l) Console.WriteLine(-1);
                }
            }
        }
    }
}