#include <bits/stdc++.h>
using namespace std;
inline void solve() {
  int n, cnt_op = 0, ans = 0;
  cin >> n;
  char c;
  while (n--) {
    cin >> c;
    if (c == '(') {
      cnt_op++;
    } else {
      cnt_op--;
      if (cnt_op < 0) {
        cnt_op++;
        ans++;
      }
    }
  }
  cout << ans << endl;
}
int main() {
  int t;
  cin >> t;
  while (t--) {
    solve();
  }
  int u;
}
