Given a string S consisting only of opening and closing parenthesis 'ie '(' and ')', find out the length of the longest valid substring.
NOTE: Length of smallest the valid substring ( ) is 2.
Input
The first line of input contains an integer T denoting the number of test cases. Then T test cases follow.
The first line of each test case contains a string S consisting only of ( and ).
Output
Print out the length of the longest valid substring.
Constraints
1 <= T <= 100
0 < S <= 110
Examples
Input
4
(()(
()()((
((()()())))
()(())(
Output
2
4
10
6
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.
mr_kksparrow | 433 |
manvirag982 | 272 |
snow_den_ | 236 |
arpit_anshuman | 228 |
Exception_404 | 220 |
blackshadows | 5331 |
Ibrahim Nash | 5219 |
akhayrutdinov | 5111 |
mb1973 | 4929 |
Quandray | 4567 |