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

int main(){
    ios::sync_with_stdio(false); cin.tie(NULL);
    int t;  cin >> t;
    while(t--){
        string a,b; cin >> a >> b;
        map<string,int> lmc;
        string aux1 = a, aux2 = b;
        for(int i = 0 ; i < 22; i++){
           lmc[a]++;
           a += aux1; 
        }
        bool flag = false;
        for(int i = 0 ; i < 22; i++){
            lmc[b]++;
            if(lmc[b] == 2){ cout << b << "\n"; flag = true; break; }
            b += aux2;
        }
        if(!flag) cout << "-1\n";
    }
    return 0;  
}   