# Arup Guha
# 2/16/2026
# Solution to COP 4516 Final Team Contest Problem: We've got the beat

# Process cases.
nC = int(input())
for loop in range(nC):

    # Get string.
    s = input().strip()

    cnt = 0
    for i in range(len(s)):

        # Just print the character.
        print(s[i], end="")

        # Update eighth note count.
        if s[i] == 'E':
            cnt += 1
        elif s[i] == 'Q':
            cnt += 2
        elif s[i] == 'H':
            cnt += 4
        else:
            cnt += 8

        # Measure so go to a new line.
        if cnt == 8:
            print()
            cnt = 0;
            
