408507: GYM103158 L Memable Ace

Memory Limit:256 MB Time Limit:1 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

L. Memable Acetime limit per test1 secondmemory limit per test256 megabytesinputmax-pair.inoutputstandard output

Pillow decided to give Khaled Hamed an easy problem and was surprised when Khaled Hamed solved it. Apparently, Pillow didn't know that blue coders can solve problems.

So we hope you all prove Pillow wrong by solving the given problem.

Given a string $$$S$$$ where $$$S_i \neq S_{i+1}$$$ for all $$$0 \leq i \leq |S| - 1$$$.

return the maximum distance between a pair $$$i$$$ and $$$j$$$ such that $$$i < j$$$ and $$$S_i \neq S_j$$$ where the distance between a pair is $$$j - i$$$.

Input

The first line contains an integer $$$T$$$ number of test cases where $$$(1 \leq T \leq 10)$$$.

The only line in each test case is the string $$$S$$$ consisting only of lowercase Latin letters where $$$(2 \leq |S| \leq 10^5)$$$.

Output

For each test case print the maximum distance between a pair satisfying the above conditions.

ExampleInput
2
abcda
ababab
Output
3
5

Source/Category

加入题单

算法标签: