for _ in range(int(input())): x = input() y = input() s = x + y t = y + x print('XY'[s < t or s == t and len(x) < len(y)])