#include <bits/stdc++.h>
using namespace std;
int main() {
  unsigned long long int t, a, b, c, d, n, x, r, v, y, i, o, j, sum;
  string s;
  cin >> t;
  while (t--) {
    cin >> n >> s;
    c = 0;
    for (i = 0; i < n; i++) {
      if (s[i] == '(') {
        for (j = i + 1; j < n; j++) {
          if (s[j] == ')') {
            c += 2;
            s[i] = '.';
            s[j] = '.';
            break;
          }
        }
      }
    }
    cout << (n - c) / 2 << endl;
  }
}
