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;
                for(int j = 2; j<Math.Sqrt(a[i]) && z; j++)
                {
                    if (a[i] % j == 0)
                    {
                        long x = j, y = a[i] / j;
                        if ((x ^ y) == b[i])
                        {
                            Console.WriteLine(x + " " + y);
                            z = false;
                        }
                    }
                }
                if (z)
                    Console.WriteLine(-1);
            }
        }
    }
}