입력값과 주기적으로 답변을 저장하는 리스트(res)의 끝값을 비교하여 append-pop을 반복한다.
for tc in range(1,int(input())+1):
arr=input()
res=[]
for i in arr:
if not res or res[-1]!=i:
res.append(i)
elif res[-1]==i:
res.pop()
print(f'#{tc} {len(res)}')