#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    string s;
    cin >> s;
    stack<char> a;
    for (int i = 0; i < n; i++) {
      if (s[i] == '(')
        a.push(s[i]);
      else {
        if (!a.empty()) a.pop();
      }
    }
    cout << a.size() << endl;
  }
}
