n = int(input())
for _ in range(n):
surname_name = input().strip()
for pos in range(1, len(surname_name)):
if surname_name[pos].isupper():
surname = surname_name[:pos]
name = surname_name[pos:]
print(name + surname)