#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    string str;
    cin >> str;
    queue<char> q;
    int index = 0, jumps = 0;
    if (str[0] == ')')
      jumps++;
    else
      q.push(str[0]);
    for (int i = 1; i < n; i++) {
      if (str[i] == '(')
        q.push(str[i]);
      else if (!q.empty()) {
        q.pop();
      } else {
        jumps++;
      }
    }
    cout << jumps << endl;
  }
  return 0;
}
