#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using pi = pair<int, int>;
using pl = pair<ll, ll>;
const ll N = 3e5 + 10;
const ll INF = 1e10;
const ll M = 1e3 + 1;
const ll L = 31;
const ll mod = 998244353;
ll solve() {
  ll n;
  cin >> n;
  string second;
  cin >> second;
  stack<ll> stk;
  ll op = 0;
  ll cl = 0;
  for (ll i = 0; i < n; i++) {
    if (second[i] == '(') {
      stk.push(i);
    } else {
      if (stk.empty()) {
        op++;
      } else {
        stk.pop();
      }
    }
  }
  cl += (stk.size());
  cout << (max(op, cl)) << '\n';
  return 0;
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  ll cas;
  cin >> cas;
  for (ll i = 0; i < cas; i++) {
    solve();
  }
  return 0;
}
