#include <bits/stdc++.h>
using namespace std;
void c_p_c() {}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t, n;
  string s;
  cin >> t;
  while (t--) {
    cin >> n;
    cin >> s;
    int count = 0;
    int cls = 0;
    int open = 0;
    for (int i = 0; i < s.size(); i++) {
      if (s[i] == '(') {
        open = open + 1;
      }
      if (s[i] == ')') {
        cls = cls + 1;
      }
      if (cls > open) {
        count = count + 1;
        cls = 0;
        open = 0;
      }
    }
    cout << count << endl;
  }
  return 0;
}
