import itertools as iter import collections as coll import heapq as hq import bisect as bis from decimal import Decimal as dec from functools import cmp_to_key import math import sys #import pypyjit #pypyjit.set_param('max_unroll_recursion=-1') sys.setrecursionlimit(10 ** 6) inp = sys.stdin.readline input = lambda : inp().rstrip() getN = lambda : int(inp()) getNs = lambda : map(int, inp().split()) getList = lambda :list(map(int, inp().split())) getStrs = lambda n : [input() for _ in [0] * n] def yexit(): print("Yes"); exit(0) def nexit(): print("No"); exit(0) pi = 3.141592653589793 mod = 1000000007 MOD = 998244353 INF = 4611686018427387903 dx = [1, 0, -1, 0]; dy = [0, 1, 0, -1] """ Main Code """ ans = [] for _ in [0] * getN(): s = input() t = input() ma = max(len(s), len(t)) mi = min(len(s), len(t)) lis1 = [s] * ((ma - 1) // len(s) + 1); ss = ''.join(lis1) lis2 = [t] * ((ma - 1) // len(t) + 1); tt = ''.join(lis2) if(ss[:ma] == tt[:ma]): if(len(s) == ma): ans.append('X') else: ans.append('Y') continue if(ss > tt): ans.append('X') else: ans.append('Y') for c in ans: print(c)