arr = [] for _ in range(int(input())): arr.append(str(max([int(i) for i in input()]))) print("".join(arr))