#include <bits/stdc++.h>
using namespace std;
signed main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  long long t;
  cin >> t;
  while (t--) {
    long long n;
    cin >> n;
    vector<char> v;
    long long ans = 0;
    for (long long i = 1; i <= n; ++i) {
      char a;
      cin >> a;
      if (a == ')') {
        if ((long long)(v).size())
          v.pop_back();
        else
          ++ans;
      } else if (a == '(')
        v.push_back(a);
    }
    ans += (long long)(v).size();
    cout << ans / 2 << '\n';
  }
}
