Valid Substring
Submissions: 9510   Accuracy:

39.09%

  Difficulty: Easy   Marks: 2
Associated Course(s):   Sudo Placement 2019

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

 

** For More Input/Output Examples Use 'Expected Output' option **

Author: Rohan Malhotra


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.



Need help with your code? Please use ide.geeksforgeeks.org, generate link and share the link here.

to report an issue on this page.