#include<bits/stdc++.h>
using namespace std;
#define fainou ios_base::sync_with_stdio(false);cin.tie(NULL)
#define ll long long
#define mod 1000000007

ll gcd(ll a,ll b){
    if(b==0) return a;
    else  return gcd(b,a%b);
}

int main(){ 
	fainou;
    ll t;
    cin>>t;
    while(t--){
        string s1,s2,S1,S2;
        cin>>s1>>s2;
        ll l1=s1.length(),l2=s2.length(),lcm;
        lcm=(l1*l2)/gcd(l1,l2);
        for(ll i=0;i<lcm/l1;i++){
            S1+=s1;
        }
        for(ll i=0;i<lcm/l2;i++){
            S2+=s2;
        }
        if(S1==S2) cout<<S1<<"\n";
        else cout<<"-1\n";
    }
    return 0;
}
