#include <bits/stdc++.h>
using namespace std;
long long t;
int main() {
  cin >> t;
  while (t--) {
    vector<int> l, r;
    long long n, ind = 1, foo = 0;
    bool test = true;
    string s;
    cin >> n >> s;
    char c[n];
    for (int i = 0; i < n; i++) {
      c[i] = s[i];
    }
    while (test) {
      for (int i = 0; i < n - ind; i++) {
        if (c[i] == '(' && c[i + ind] == ')') {
          c[i] = '?';
          c[i + ind] = '?';
        }
      }
      ind++;
      if (ind >= n) test = false;
    }
    for (int i = 0; i < n; i++) {
      if (c[i] == '(') l.push_back(i);
      if (c[i] == ')') r.push_back(i);
    }
    sort(l.begin(), l.end());
    sort(r.begin(), r.end());
    for (int i = 0; i < l.size(); i++) {
      if (r[i] < l[i]) foo++;
    }
    cout << foo << '\n';
  }
  return 0;
}
