#include<iostream>
#include<cmath>
using namespace std;
int main()
{
    long long a[10000],b[10000];
    long t,t1,m,t2,x,y,k;
    m=0;
    cin>>t;
    for(t1=1;t1<=t;t1++)
    {
     k=0;
        cin>>a[t1];
        cin>>b[t1];
        m++;
        for(t2=1;t2*t2<a[t1];t2++)
        {
            if(a[t1]%t2==0)
            {
                x=t2;
                y=a[t1]/t2;
                if(b[t1]==(x^y))
                {
                    cout<<x;
                    cout<<y;
                    k=1;
                    goto endloop;
                }
            }
        }
        endloop:
        m++;
        if (k==0)
        {
            cout<<"-1";
        }

    }

}