def solve(): X = input() Y = input() lX = len(X) lY = len(Y) l = max(len(X),len(Y))*2 for i in range(l): x,y = X[i%lX],Y[i%lY] if x > y: return "X" elif x < y: return "Y" if lX < lY: return "Y" else: return "X" t = int(input()) for _ in range(t): print(solve())