#include <iostream>

#define sz(x) (int)(x.size())

using namespace std;

void solve() {
	string s, t;
	cin >> s >> t;
	
	if(sz(s) < sz(t)) swap(s, t);
	
	string S = s, T = t;
	for(int i = 0; i < 20; i++) {
		if(S == T) {
			cout << S << '\n';
			return;
		}
		
		T += t;
		if(sz(T) > sz(S)) S += s;
	}
	
	cout << -1 << '\n';
}

int main() {
	int T;
	cin >> T;
	
	while(T--) solve();
	
	return 0;
}