#K5646. Longest Alphabetical Substring

    ID: 30203 Type: Default 1000ms 256MiB

Longest Alphabetical Substring

Longest Alphabetical Substring

You are given a string s consisting of lowercase English letters. Your task is to determine the length of the longest substring in which the characters appear in non-decreasing order according to the English alphabet. In other words, find the maximum length L such that there exists a substring s[i...j] where for every k (i+1 ≤ k ≤ j), the inequality s[k-1] ≤ s[k] holds.

For example, if s = "ababc", then the longest substring in alphabetical order is "aba" or "abc" with length 3.

Note: A substring is a contiguous sequence of characters within the string.

The relationship between consecutive characters in the English alphabet can be formalized using the lexicographical order relation: \[ s[k-1] \leq s[k]\] for all valid indices in the substring.

inputFormat

The first line of input contains a single integer t (t ≥ 1) representing the number of test cases.

Each of the following t lines contains a non-empty string s consisting of lowercase English letters.

outputFormat

For each test case, output a single line containing the length of the longest substring of s whose characters are in non-decreasing alphabetical order.

## sample
1
a
1

</p>