#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  srand(time(0));
  int t;
  cin >> t;
  while (t--) {
    int n;
    string s;
    cin >> n >> s;
    int ans = 0;
    int cur = 0;
    for (int i = 0; i < s.size(); i++) {
      if (s[i] == '(')
        cur++;
      else
        cur--;
      if (cur < 0) {
        ans++;
        cur = 0;
      }
    }
    cout << ans << "\n";
  }
}
