#include <bits/stdc++.h>
using namespace std;
int main() {
  long long t;
  scanf("%lld", &t);
  string s;
  int x;
  for (int i = 1; i <= t; i++) {
    cin >> x;
    cin >> s;
    int count = 0;
    int minm = 0;
    for (int j = 0; j < s.length(); j++) {
      if (s[j] == ')') {
        count--;
        if (count < 0) {
          minm++;
          count = 0;
        }
      } else {
        count++;
      }
    }
    cout << minm << endl;
  }
  return 0;
}
