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