#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int tc;
  cin >> tc;
  while (tc--) {
    string s;
    int n, x = 0, y = 0;
    bool vis[55];
    memset(vis, false, sizeof(vis));
    vector<int> f;
    cin >> n >> s;
    for (int i = 0; i < n; i++) {
      if (s[i] == '(')
        f.push_back(i);
      else {
        int z = f.size();
        if (z) {
          vis[f[z - 1]] = true;
          vis[i] = true;
          f.pop_back();
        }
      }
    }
    for (int i = 0; i < n; i++) {
      if (vis[i] == false) {
        if (s[i] == '(')
          x++;
        else
          y++;
      }
    }
    cout << min(x, y) << endl;
  }
  return 0;
}
