#K33617. Beautiful Alternating Pattern

    ID: 25128 Type: Default 1000ms 256MiB

Beautiful Alternating Pattern

Beautiful Alternating Pattern

You are given several strings of stones. Each stone is represented by a lowercase English letter which denotes its color. A beautiful pattern is defined as a contiguous substring where no two adjacent stones are of the same color. Your task is to determine, for each string, the maximum number of stones that you can choose such that they form a beautiful pattern.

In other words, for a given string s of length n, find the maximum length of a contiguous segment in which every two consecutive characters are different. If the string is empty, then the answer is 0.

Note: The input is provided via standard input (stdin) and the output should be printed to standard output (stdout). The first line of input contains an integer T representing the number of test cases. Each of the next T lines consists of a string of stones for which you need to compute the answer.

inputFormat

The input begins with an integer T on a single line, representing the number of test cases. This is followed by T lines, each containing a string s made up of lowercase English letters. Each string represents a sequence of stones.

Constraints:

  1. 0 ≤ length of s ≤ 105
  2. 1 ≤ T ≤ 104

outputFormat

For each test case, output a single integer on a new line — the maximum number of stones that can form a beautiful alternating pattern (i.e., a contiguous substring where no two consecutive stones are the same).

## sample
1
abacaba
7