t = int(input()) for i in range(t): x = input() y = input() lx = len(x) ly = len(y) f = False for j in range(max(lx,ly)): if x[j%lx] < y[j%ly]: f = True print("Y") break elif x[j%lx] < y[j%ly]: f = True print("X") break if f == False: if lx < ly: print("Y") else: print("X")