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

namespace petlja1E
{
    class Program
    {
        static void Main(string[] args)
        {
            int t = int.Parse(Console.ReadLine());
            long[] a = new long[t], b = new long[t];
            for(int i = 0; i<t; i++)
            {
                string[] u = Console.ReadLine().Split(' ');
                a[i] = Convert.ToInt64(u[0]);
                b[i] = Convert.ToInt64(u[1]);
            }
            
            for(int i = 0; i<t; i++)
            {
                bool z = true;
                if (a[i] % 2 == 0)
                {
                    if ((2 ^ a[i] / 2) == b[i])
                    {
                        Console.WriteLine(2 + " " + a[i] / 2);
                        z = false;
                    }
                }
                for (int j = 3; j<Math.Sqrt(a[i]) && z; j+=2)
                {
                    if (a[i] % j == 0)
                    {
                        if ((j ^ a[i] / j) == b[i])
                        {
                            Console.WriteLine(j + " " + a[i] / j);
                            z = false;
                        }
                    }
                }
                if (z)
                    Console.WriteLine(-1);
            }
        }
    }
}