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() ans = 'X' if len(s) > len(t): p = 1 while len(s) > p * len(t): p += 1 t = t * p else: ans = 'Y' p = 1 while len(t) > p * len(s): p += 1 s = s * p 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 print(ans) for _ in range(ii()): solve()