from math import gcd def solve(x, y): a = len(x) b = len(y) g = gcd(a, b) s = x[:g] if x == s*(a//g) and y == s*(b//g): return 'X' if a > b else 'Y' i = 0 while True: p = ord(x[i % a]) q = ord(y[i % b]) if p > q: return 'X' elif p < q: return 'Y' else: i += 1 def main(): T = int(input()) ans = [] for _ in range(T): x = input() y = input() ans.append(solve(x, y)) print(*ans, sep='\n') main()