N = int(input()) for _ in range(N): x = input() y = input() if x < y: if len(x) >= len(y): print("Y") else: k = (len(y)//len(x)+1)*2 if (x*k)[:len(y)*2] <= y*2: print("Y") else: print("X") else: if len(x) <= len(y): print("X") else: k = len(x)//len(y)+1 if (y*k)[:len(x)*2] <= x*2: print("X") else: print("Y")