#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, con, ss = 0, qw = 0, q = 0, asd;
  cin >> n;
  string s;
  int qwe[n];
  for (int i = 0; i < n; i++) {
    cin >> con;
    cin >> s;
    for (int l = 0; l < con; l++) {
      if (s[l] == '(') {
        if (l > q)
          asd = l + 1;
        else
          asd = q + 1;
        for (q = asd; q < con; q++) {
          if (s[q] == ')') {
            qw++;
            break;
          }
        }
      }
    }
    qw = qw * 2;
    qw = con - qw;
    qw = qw / 2;
    qwe[i] = qw;
    ss = 0;
    qw = 0;
    q = 0;
  }
  for (int i = 0; i < n; i++) {
    cout << qwe[i] << endl;
  }
}
