#include <bits/stdc++.h>
using namespace std;
template <typename T1, typename T2>
istream& operator>>(istream& in, pair<T1, T2>& a) {
  in >> a.first >> a.second;
  return in;
}
template <typename T1, typename T2>
ostream& operator<<(ostream& out, pair<T1, T2> a) {
  out << a.first << " " << a.second;
  return out;
}
template <typename T, typename T1>
T amax(T& a, T1 b) {
  if (b > a) a = b;
  return a;
}
template <typename T, typename T1>
T amin(T& a, T1 b) {
  if (b < a) a = b;
  return a;
}
const long long INF = 1e18;
const int32_t M = 1e9 + 7;
const int32_t MM = 998244353;
const long long int N = 0;
long long int pw(long long int a, long long int p = M - 2,
                 long long int MOD = M) {
  long long int result = 1;
  while (p > 0) {
    if (p & 1) result = a * result % MOD;
    a = a * a % MOD;
    p >>= 1;
  }
  return result;
}
void bfs(long long int n) {
  vector<long long int> graph[N];
  queue<long long int> q;
  vector<bool> used(N, 0);
  vector<long long int> d(N), p(N);
  long long int s = n;
  q.push(s);
  used[s] = true;
  p[s] = -1;
  while (!q.empty()) {
    long long int v = q.front();
    q.pop();
    for (long long int u : graph[v]) {
      if (!used[u]) {
        used[u] = true;
        q.push(u);
        d[u] = d[v] + 1;
        p[u] = v;
      }
    }
  }
}
void richierich() {
  long long int n;
  cin >> n;
  string s;
  cin >> s;
  long long int ans = 0, bal = 0;
  for (long long int i = 0; i < n; i++) {
    if (s[i] == '(')
      bal++;
    else {
      bal--;
      if (bal < 0) {
        ans -= bal;
        bal = 0;
      }
    }
  }
  cout << ans << "\n";
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long int t = 1;
  cin >> t;
  while (t--) richierich();
  return 0;
}
