#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie();
  ;
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    char b;
    int co = 0, cco = 0, ans = 0;
    for (int i = 0; i < n; i++) {
      cin >> b;
      if (b == '(')
        co++;
      else
        co--;
      if (co < 0) ans++, co = 0;
    }
    cout << ans << endl;
  }
}
