CF2178B.Impost or Sus

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

Impost or Sus

A string ww consisting of lowercase Latin letters is called suspicious if and only if all of the following conditions hold:

  • The letter s appears at least twice, and
  • For every occurrence of the letter u, the two nearest occurrences of s are the same number of characters away from the u.

After watching you finish a string task, your friend Aka has gifted you a string rr consisting only of letters s and u. You can perform the following operation on rr:

  • Choose an index ii (1ir1\le i\le |r|), and set rir_i to s.

Determine the minimum number of operations needed to make rr suspicious. It can be shown that, under the given constraints, it is always possible to transform rr into a suspicious string.

Input

Each test contains multiple test cases. The first line contains the number of test cases tt (1t1041 \le t \le 10^4). The description of the test cases follows.

The only line of each test case contains the string rr (3r21053\le |r|\le 2\cdot 10^5). It is guaranteed that ri=sr_i = \mathtt{s} or u.

It is guaranteed that the sum of r|r| over all test cases does not exceed 21052\cdot 10 ^ 5.

Output

For each test case, output a single integer — the minimum number of operations needed to make rr suspicious.

Note

In the first test case, the string sus is already suspicious because s appears twice in the string and the two nearest s to the only u are both 11 character away: $\color{red}{\mathtt{s}}\underline{\mathtt{u}}\color{red}{\mathtt{s}}$.

In the second test case, it is optimal to perform the operation on indices 11, 33, and 44. After that, the string ss becomes suss. The string suss is suspicious because s appears 33 times in the string and the two nearest s to the only u are both 11 character away: $\color{red}{\mathtt{s}}\underline{\mathtt{u}}\color{red}{\mathtt{s}}\mathtt{s}$.

In the third test case, the condition on u is vacuously true because there is no u in the string sssss. Thus, the given string is already suspicious.

In the sixth test case, the initial string usssssss is not suspicious because the two nearest s to the only u are one and two characters away, respectively: $\underline{\mathtt{u}}\color{red}{\mathtt{ss}}\mathtt{sssss}$.

Samples

9
sus
uuuu
sssss
uusuuu
suuuuuu
usssssss
sssuuusss
susuusuuus
uuuuuuuuuuu
0
3
0
3
3
1
1
2
6

在线编程 IDE

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