#双指针
def main():
n = int(input())
for _ in range(n):
s = list(input())
p1 = 0
for p2 in range(len(s)):
s[p1] = s[p2]
p1 += 1
if p1 >= 3 and s[p1 - 1] == s[p1 - 2] == s[p1 - 3]:
p1 -= 1
elif p1 >= 4 and s[p1 - 1] == s[p1 - 2] and s[p1 - 3] == s[p1 - 4]:
p1 -= 1
print(''.join(s[0:p1 ]))
# p1 穿过index 不含p1
main()