#include <bits/stdc++.h>
using namespace std;
void solve() {
  int n;
  cin >> n;
  string s;
  cin >> s;
  vector<char> v;
  for (int i = 0; i < n; i++) {
    if (s[i] == '(') {
      v.push_back(s.at(i));
    } else {
      if (v.size() > 0) {
        if (v.back() == '(') {
          v.pop_back();
        } else
          v.push_back(s.at(i));
      } else {
        v.push_back(s.at(i));
      }
    }
  }
  cout << v.size() / 2 << endl;
  v.clear();
}
int main() {
  int t;
  cin >> t;
  while (t--) {
    solve();
  }
}
