#include <bits/stdc++.h>
using namespace std;
int count(string s, int n) {
  int j = 0, res = 0;
  for (int i = 0; i < n; i++) {
    if (s[i] == '(') {
      j++;
    } else {
      j--;
    }
    if (j < 0) {
      res++;
      j = 0;
    }
  }
  return res;
}
int main() {
  int t;
  int n;
  int j;
  cin >> t;
  j = t;
  vector<int> res(t);
  while (t > 0) {
    cin >> n;
    string s;
    cin >> s;
    res[j - t] = count(s, n);
    t--;
  }
  for (int k = 0; k < j; k++) cout << res[k] << endl;
  return 0;
}
