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

namespace Zadatak_5
{
    class Program
    {
        static void Main(string[] args)
        {
            int t = int.Parse(Console.ReadLine());
            long[] a = new long[t];
            long[] b = new long[t];
            for(int i = 0; i < t; i++)
            {
                string pom = Console.ReadLine();
                string[] pom1 = pom.Split(' ');
                a[i] = Convert.ToInt64(pom1[0]);
                b[i] = Convert.ToInt64(pom1[1]);
            }
            for (int j = 0; j < t; j++)
            {
                Delioci(a[j], b[j]);
            }

        }
        static string VratiBinarni(long n)
        {
            string pom=Convert.ToString(n, 2);
            return pom;
        }
        static string XoR(long a1,long b1)
        {
            string a = VratiBinarni(a1);
            string b = VratiBinarni(b1);
            while (a.Length != b.Length)
            {
                if (a.Length > b.Length)
                {
                    b="0"+b;
                }
                else if (a.Length < b.Length)
                {
                    a="0"+a;
                }
            }
            string c="";
            while(a!="")
            {
                if (a[0] % 10 == b[0] % 10)
                    c+="0";
                else
                    c +="1";
                a = a.Remove(0, 1);
                b = b.Remove(0, 1);
            }
            Console.WriteLine(c);
            return c;
            
        }
        static bool Delioci(long n,long m)
        {
            for (long i = 1; i <= n/2; i++)
            {
                if (n % i == 0)
                {
                    if (VratiDecimalni(XoR(i, n / i)) == m)
                    {
                        Console.WriteLine("{0} {1}", i, n / i);
                        return true;
                    }
                }
            }
            Console.WriteLine("-1");
            return false;
        }
        static long VratiDecimalni(string unos)
        {
            char[] niz = unos.ToCharArray();
            Array.Reverse(niz);
            long sum = 0;

            for (long i = 0; i < niz.Length; i++)
            {
                if (niz[i] == '1')
                { 
                    if (i == 0)
                    {
                        sum += 1;
                    }
                    else
                    {
                        sum += (long)Math.Pow(2, i);
                    }
                }
            }
            return sum;
        }
    }
}