#include<bits/stdc++.h>
using namespace std;
int main(){
int T;
cin>>T;
while(T--){
//stack need to be inside
stack<int> stack;
string s;
cin>>s;
int count=0;
for(auto c : s){
if(!stack.empty() && c==')' && stack.top()=='(') {
stack.pop();
count++;
} else {
stack.push(c);
}
}
if(stack.empty()){
cout<<count<<"\n";
} else {
cout<< "0" <<"\n";
}
}
}
To embed this project on your website, copy the following code and paste it into your website's HTML: