#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie();
  long long t;
  cin >> t;
  while (t--) {
    long long a;
    cin >> a;
    string s;
    cin >> s;
    long long n = s.length();
    long long open = 0, close = 0;
    long long wrong = 0, total = 0;
    for (long long i = 0; i < n; i++) {
      if (s[i] == '(') {
        open++;
      } else {
        close++;
      }
      if (close > open) {
        wrong++;
        open = 0;
        close = 0;
        total++;
      }
    }
    cout << total << "\n";
  }
  return 0;
}
