t = int(input()) for _ in range(t): x = list(input()) x += x y = list(input()) y += y if len(x) >= len(y): for i in range(len(y), len(x)): y.append(y[i % len(y)]) if x >= y: print('X') else: print('Y') else: for i in range(len(x), len(y)): x.append(x[i % len(x)]) if x > y: print('X') else: print('Y')