#include <bits/stdc++.h>
using namespace std;
int n, t, ans;
int main() {
  int t;
  cin >> t;
  while (t--) {
    ans = 0;
    cin >> n;
    int a[55];
    char b[55];
    cin >> b;
    for (int i = 0; i < n; i++) {
      a[i] = 0;
    }
    for (int i = 0; i < n; i++) {
      if (b[i] == '(' && a[i] == 0) {
        for (int j = i + 1; j < n; j++) {
          if (b[j] == ')' && a[j] == 0) {
            a[i] = 1;
            a[j] = 1;
            break;
          }
        }
      }
    }
    for (int i = 0; i < n; i++) {
      if (a[i] == 0) ans++;
    }
    cout << ans / 2 << endl;
  }
  return 0;
}
