Mr. Binary
Easy Accuracy: 17.24% Submissions: 1679 Points: 2

Mr. Binary is a very greedy person. He always finds a path to do a job with minimum expense. This time his mother has asked him to go to a grocery store to buy some food items. Path to grocery store is represented by a string s containing lower case English alphabets. He can only jump to some other location j (j>i) only if s[j] = s[i]+1. He wants to find out the maximum distance he can reach, i.e., maximum index of the string he can reach.

Note: First character of the string is always 'a'. He can only go 'a'->'b','b'->'c','c'->'d' and so on. 'a'->'c','b'->'d','b'->'a' is not a valid move. He can start from any of index of 'a'. Indexing is zero based.

Input:
First line contains single integer defining the number of test cases T.Each of the next T lines contain a single string s containing only lower case english letters.

Output:
For each test case in a new line print a single integer denoting the answer for each test case.

Constraints:
1<=T<=30
1<=|s|<=10^5

Example:
Input

2
aaabbcdbdt
aabcb

Output:
8
4

Explanation:

For first test case
He can start from 'a' at index 0 or 1 or 2 and then move to 'b' at index 3 or 4, then jump to 'c' at index 5 and then go to  'd' at greater index than 6 which is 8. Thus the answer is 8.

For second test case
In second test case, again he starts from 'a' and proceed to 'b' and then 'c'. But we have 'b' at the highest index also, so he will not go to 'c' and from 'a', we will directly jump to 'b'.

to report an issue on this page.

### Editorial

We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?