Move Brackets#11788

Move Brackets

1 second
128 megabytes
Easy

A bracket sequence of length is given, containing exactly opening brackets '(' and closing brackets ')'.

In one move, you can select a single bracket and move it to the beginning or the end of the string (i.e., you can choose some index , remove the -th character from , and insert it before or after all other characters in ).

Find the minimum number of moves required to transform into a valid bracket sequence. It is guaranteed that such a transformation is always possible.

Definition of a valid bracket sequence:

For example, the strings "()()", "(())()", "(())" and are valid bracket sequences, while ")(", "()(" and are not.

Input

The first line contains the number of test cases t~(1 \le t \le 2000).

Each of the following lines represents a separate test case and contains a string of even length, consisting of opening brackets and closing brackets ( is an even number).

Output

For each test case, print the minimum number of moves required to transform the string into a valid bracket sequence. It is guaranteed that a solution always exists.

Examples

Example 1

Loading
Loading