CF2062A.String

传统题 时间 2000 ms 内存 256 MiB 3 尝试 1 已通过 1 标签

String

You are given a string ss of length nn consisting of 0 and/or 1. In one operation, you can select a non-empty subsequence tt from ss such that any two adjacent characters in tt are different. Then, you flip each character of tt (0 becomes 1 and 1 becomes 0). For example, if s=00101s=\mathtt{\underline{0}0\underline{101}} and t=s1s3s4s5=0101t=s_1s_3s_4s_5=\mathtt{0101}, after the operation, ss becomes \underline{1}0\underline{010}.

Calculate the minimum number of operations required to change all characters in ss to 0.

Recall that for a string s=s1s2sns = s_1s_2\ldots s_n, any string t=si1si2sikt=s_{i_1}s_{i_2}\ldots s_{i_k} (k1k\ge 1) where 1i1<i2<<ikn1\leq i_1 \lt i_2 \lt \ldots \lt i_k\leq n is a subsequence of ss.

Input

The first line of input contains a single integer tt (1t1041 \leq t \leq 10^4) — the number of input test cases.

The only line of each test case contains the string ss (1s501\le |s|\le 50), where s|s| represents the length of ss.

Output

For each test case, output the minimum number of operations required to change all characters in ss to 0.

Note

In the first test case, you can flip s1s_1. Then ss becomes 0, so the answer is 11.

In the fourth test case, you can perform the following three operations in order:

  1. Flip s1s2s3s4s5s_1s_2s_3s_4s_5. Then ss becomes \underline{01010}.
  2. Flip s2s3s4s_2s_3s_4. Then ss becomes 0\underline{010}0.
  3. Flip s3s_3. Then ss becomes 00\underline{0}00.

It can be shown that you can not change all characters in ss to 0 in less than three operations, so the answer is 33.

Samples

5
1
000
1001
10101
01100101011101
1
0
2
3
8

在线编程 IDE

建议全屏模式获得最佳体验