import sys def main(): t = int(input()) Q = sys.stdin.read().split() for qi in range(t): X = Q[2*qi] Y = Q[2*qi+1] nx, ny = len(X), len(Y) ok = False for i in range(max(nx, ny)): xi = i if i < nx else i % nx yi = i if i < ny else i % ny if X[xi] > Y[yi]: print('X') ok = True elif X[xi] < Y[yi]: print('Y') ok = True else: continue break if not ok: print('X' if nx > ny else 'Y') if __name__ == '__main__': main()