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());
            int p = 0;
            long[] u = new long[2 * n];
            ulong a, b, k;
            int q;
            for (int i = 0; i < n; i++)
            {
                q = 0;
                string[] s = Console.ReadLine().Split();
                a = ulong.Parse(s[0]);
                b = ulong.Parse(s[1]);
                k = (ulong)Math.Sqrt(a);
                for (ulong j = 1; j <= k; j++) 
                {
                    if (j % 2 != 0 && a % j == 0 && (ulong)((long)j ^ (long)(a / j)) == b)
                    {
                        u[p] = (long)j;
                        u[p + 1] = (long)(a / j);
                        q++;
                    }                   
                }
                if (q == 0) u[p] = -1;
                p = p + 2;
            }
            for (int i = 0; i < p; i = i + 2)
            {
                if (u[i] == -1) Console.WriteLine(u[i]);
                else Console.WriteLine(u[i] + " " + u[i + 1]);
            }
        }
    }
}