#include<bits/stdc++.h>
using namespace std;

int gcd(int a, int b)
{
  if (b == 0)
    return a;
  return gcd(b, a % b);
}
 
// Function to return LCM of two numbers 
int lcm(int a, int b)
{
    return (a / gcd(a, b)) * b;
}

int main(){
    int t;
    cin>>t;
    while(t--){
        string s,t;
        cin>>s>>t;
        int n = s.size();
        int m = t.size();
        int l = lcm(n,m);
        string s1,s2;
        int n1 = l/n , n2 = l/m;
        for(int i=0; i<n1; i++){
            s1+=s;
        }
        for(int i=0; i<n2; i++){
            s2+=t;
        }
        if(s1==s2){
            cout<<s1<<endl;
        }
        else{
            cout<<-1<<endl;
        }
    }
}
