// Scaena Felix.cpp #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define LL long long #define lson l, m, rt<<1 #define rson m+1, r, rt<<1|1 #define PI 3.1415926535897932626 #define EXIT exit(0); #define PAUSE system("pause"); #define DEBUG puts("Here is a BUG"); #define SYNC_CLOSE ios::sync_with_stdio(false); #define what_is(x) cout << #x << " is " << x << endl; #define CLEAR(name, init) memset(name, init, sizeof(name)); const double eps = 1e-8; const int MAXN = (int)1e9 + 5; using namespace std; int main(int argc, char const *argv[]) { #ifndef ONLINE_JUDGE freopen("D:\\Documents\\Disk_Synchronous\\Programs\\Acm\\input.txt", "r", stdin); #endif int T; cin >> T; while(T--) { string s; cin >> s; int lft = 0, res = 0; for(int i = 0; s[i]; i++) { if (s[i] == '(') lft++; else { if (lft > 0) { res++; lft--; } } } cout << res << endl; } return 0; }