#include <bits/stdc++.h>
using namespace std;
void primeFacTillN(long n) {
  bool p[1000000] = {0};
  p[0] = 1;
  p[1] = 1;
  int i = 0;
  for (int i = 2; i <= n; i++) {
    if (!p[i]) {
      for (int j = 2 * i; j <= n; j += i) p[j] = 1;
    }
  }
}
int main() {
  long t;
  cin >> t;
  while (t--) {
    long n;
    cin >> n;
    string a;
    cin >> a;
    long ans = 0, open = 0, close = 0;
    long i;
    for (i = 0; i < a.length(); i++) {
      if (a[i] == '(')
        open++;
      else {
        close++;
      }
      if (close > open) {
        ans += close - open;
        close = open;
      }
    }
    cout << ans << "\n";
  }
  return 0;
}
