import sys input = lambda: sys.stdin.readline().rstrip() ii = lambda: int(input()) mi = lambda: map(int, input().split()) li = lambda: list(mi()) INF = 2 ** 63 - 1 mod = 998244353 def solve(): s = input() t = input() n = len(s) m = len(t) p = 1 while len(s) > p * len(t): p += 1 t = t * (p + 1) p = 1 while len(t) > p * len(s): p += 1 s = s * (p + 1) for i in range(min(len(s), len(t))): if s[i] > t[i]: ans = 'X' break elif s[i] < t[i]: ans = 'Y' break else: if n < m: ans = 'Y' else: ans = 'X' print(ans) for _ in range(ii()): solve()