#include <bits/stdc++.h>
using namespace std;
void solve() {
  int n;
  cin >> n;
  string s;
  cin >> s;
  stack<char> stack;
  int left = 0, right = 0, size = 0;
  for (int i = 0; i < s.length(); i++) {
    stack.push(s[i]);
    if (s[i] == '(') {
      left++;
      continue;
    }
    if (s[i] == ')' && left != 0) {
      left--;
      stack.pop();
      continue;
    }
    if (s[i] == ')' && left == 0) {
      right++;
      continue;
    }
  }
  cout << left << '\n';
}
int main() {
  int t;
  cin >> t;
  while (t--) {
    solve();
  }
}
