#include <bits/stdc++.h>
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  long long t;
  cin >> t;
  while (t--) {
    long long n;
    cin >> n;
    string s;
    cin >> s;
    stack<char> v;
    long long a = 0;
    for (long long i = 0; i < n; i++) {
      if (s[i] == '(') {
        v.push(s[i]);
      }
      if (s[i] == ')') {
        if (v.empty()) {
          a++;
        } else {
          v.pop();
        }
      }
    }
    cout << a << "\n";
  }
}
