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'.

Author: justrelax

If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.

Sulagna | 117 |

RUTVIKHARIPARA | 116 |

janvidavda105190 | 93 |

harshsiddhapura105461 | 93 |

madhursengar24 | 86 |

PiyushPandey4 | 617 |

ASWATHAMA | 561 |

akhyasharma01 | 547 |

john_wick | 521 |

jagrit_07 | 448 |

blackshadows | 5362 |

Ibrahim Nash | 5242 |

akhayrutdinov | 5111 |

mb1973 | 4929 |

Quandray | 4598 |

Login to report an issue on this page.