def div(n): S = set() i = 1 while i * i <= n: if n % i == 0: S.add(i) S.add(n // i) i += 1 return list(S) T = int(input()) ans = ["X", "Y"] for _ in range(T): X = list(input()) Y = list(input()) flag = 0 if len(X) <= len(Y): flag = 1 X, Y = Y, X minv = 10 ** 18 for d in div(len(Y)): S = set() for i in range(len(Y)//d): S.add(tuple(Y[i * d:(i + 1)*d])) if len(S) == 2: break if len(S) == 1 and d < minv: minv = d ylst = Y[:d] ind = 0 d = minv for i in range(len(X)//d): xlst = X[i * d:(i + 1)*d] if ylst < xlst: ind = 0 break elif ylst > xlst: ind = 1 break else: if len(X) % d == 0: ind = 0 else: xlst = X[len(X)//d * d:] * ((len(X[len(X)//d * d:]) + d - 1)//d) if ylst < xlst: ind = 0 elif ylst > xlst: ind = 1 print(ans[ind^flag])