#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    char ch;
    string str;
    cin >> str;
    int n1 = 0, n2 = 0;
    int ct = 0;
    for (int i = 0; i < n; i++) {
      if (str[i] == '(') {
        if (n2 > 0) {
          if (n2 > n1) {
            n2 = 0;
            n1 = 0;
          } else {
            n1 -= n2;
            n2 = 0;
          }
        }
        n1++;
      } else {
        n2++;
        if (n2 > n1) ct++;
      }
    }
    cout << ct << endl;
  }
  return 0;
}
