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