TopCoder

User's AC Ratio

NaN% (0/0)

Submission's AC Ratio

NaN% (0/0)

Tags

Description

In the Hackneyed Technocrat Center (HTC for short), everyone there write desultory codes with decrepit coding style. Unfortunately, you are exactly the manager of a desperate project that even yourself would like to discard it once got a chance. Fortunately, your dexterous skill save you and now you’re discreetly doing the refactoring on the codes that your team made.


All the codes were written in binary, and, since you are in Triangle Country, a good coding style includes removing discombobulated even palindromes from the codes. It turns out that the main job is to simplify the code. To preserve the correctness on function of the codes, whenever an even length palindrome is detected, one may remove the right part without any harm. (If you don’t know which is the right part, it’s the right part that after removing no part of the right part left.)


Now the dreary problem comes up, what is the minimum length of the code that needs to stay if you choose the order of palindrome elimination correctly?


For example, “0110” can be refactored into “010” or “01”, where “01” is shortest one and cannot be shorten anymore.

Input Format

First line contains an integer T(1<=T<=500) indicating the number of test cases.


For each test case there is a line containing a non-empty binary string of length no more than 2012.

Output Format

For each test case, please output the minimum length of the code that can be refactored.

Sample Input 1

3
0110
1010101
00

Sample Output 1

2
7
1

Hints

Problem Source

Migrated from old NTUJ.

Shik and Tmt

Subtasks

No. Testdata Range Score

Testdata and Limits

No. Time Limit (ms) Memory Limit (VSS, KiB) Output Limit (KiB) Subtasks
0 1000 65536 200