#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    int ans = 0, count = 0;
    string s;
    cin >> s;
    for (int i = 0; i < n; i++) {
      if (s[i] == '(')
        count++;
      else {
        count--;
        if (count < 0) {
          ans++;
          count = 0;
        }
      }
    }
    cout << ans << endl;
  }
}
