#include <bits/stdc++.h>
using namespace std;
const long long N = 1e7 + 3;
const long long md = 998244353;
const long long inf = 1e18;
int main() {
  long long i, j, w, x, k, q, n, m, v, R = 1, p, zz = 0, y, r;
  cin >> q;
  while (q--) {
    cin >> n;
    string s;
    cin >> s;
    r = 0;
    R = 0;
    for (long long i = 0; i < (n); i++) {
      if (s[i] == '(')
        r++;
      else
        r--;
      R = max(R, -r);
    }
    cout << R << '\n';
  }
}
namespace {
auto fast_io = [] {
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(nullptr);
  return 0;
}();
}
