#include <bits/stdc++.h>
using namespace std;
int main() {
  int t, n;
  string s;
  cin >> t;
  while (t--) {
    int a = 0, b = 0;
    cin >> n;
    cin >> s;
    for (int i = 0; i < s.size(); i++) {
      if (s[i] == '(') a++;
      if (s[i] == ')') a--;
      b = min(a, b);
    }
    cout << abs(b) << endl;
  }
}
