 #include <bits/stdc++.h>
    #include <string.h>
    using namespace std;
    
    #define ar array
    #define ll long long
    #define pb push_back
    #define fr(i,n) for(int i=0;i<n;i++)
    
    const int MAX_N = 1e5 + 1;
    const int MOD = 1e9 + 7;
    const int INF = 1e9;
    const ll LINF = 1e18;
    ll power(ll x, ll y, ll M) {ll res = 1; while (y > 0) {if (y & 1) res = (res * x) % M; y >>= 1; x = (x * x) % M;} return res % M;}
    ll power(ll x, ll y) {ll res = 1; while (y > 0) {if (y & 1) res = (res * x); y >>= 1; x = (x * x);} return res;}
    
    bool sortcol( const vector<ll>& v1, const vector<ll>& v2 ) { 
 return v1[0] < v2[0]; 
} 

void sortArr(vector<pair<ll, ll> > & vp,vector<ll> v, int n) 
            { 
    for (int i = 0; i < n; ++i) { 
        vp.push_back(make_pair(v[i], i)); 
    } 
  
    sort(vp.begin(), vp.end()); 
} 

int max(int a, int b) { return (a > b)? a : b; } 
int max(int a, int b, int c) { return max(max(a, b), c); } 
int maxCrossingSum(int arr[], int l, int m, int h) 
{ 
    int sum = 0; 
    int left_sum = INT_MIN; 
    for (int i = m; i >= l; i--) 
    { 
        sum = sum + arr[i]; 
        if (sum > left_sum) 
          left_sum = sum; 
    } 
    sum = 0; 
    int right_sum = INT_MIN; 
    for (int i = m+1; i <= h; i++) 
    { 
        sum = sum + arr[i]; 
        if (sum > right_sum) 
          right_sum = sum; 
    } 
    return max(left_sum + right_sum, left_sum, right_sum); 
} 
int maxSubArraySum(int arr[], int l, int h) 
{ 
   if (l == h) 
     return arr[l];
   int m = (l + h)/2; 
   return max(maxSubArraySum(arr, l, m), 
              maxSubArraySum(arr, m+1, h), 
              maxCrossingSum(arr, l, m, h)); 
} 
bool isPalindrome(string str)
{
    int j = str.length() - 1;

    for (int i = 0; i < j; i++, j--)
    {
        if (str[i] != str[j])
        {
            return false;
        }
    }

    return true;
}

    void solve() {
        string a,b;
        cin>>a;
        cin>>b;
        if(a.length()>b.length())
        {
            string c=b;
            b=a;
            a=c;
        }
        string r=a;
        int f=0;
        int g=-1;
        int l=a.length()*b.length();
        while(r.length()<=l)
        {
            if(r.length()>=b.length())
            {
            fr(i,r.length())
            {
                // cout<<i%(b.length());
                if(r[i]!=b[i%b.length()])
                {
                    f=1;
                    break;
                }
            }
            g=r.length()%b.length();
            if(f==1)
                break;
            if(g==0)
                break;

        }
        
            r+=a;
        }
        if(f==1 || g!=0)
            cout<<-1;
        else
            cout<<r;
        cout<<endl;
    }
   
    int main() {
        ios_base::sync_with_stdio(0);
        #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("error.txt", "w", stderr);
        freopen("output.txt", "w", stdout);
        #endif
        cin.tie(0); cout.tie(0);
    
        int tc; cin>>tc;
        fr(t,tc) {
            // cout<<"Case #"<<t<<": ";
            solve();
        }
    }
