#include <bits/stdc++.h>
using namespace std;
bool isPrime(long long n) {
  for (long long i = 2; i * i <= n; i++) {
    if (n % i == 0) return false;
  }
  return true;
}
long long gcd(long long a, long long b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
long long findlcm(vector<long long> arr, long long n) {
  long long ans = arr[0];
  for (long long i = 1; i < n; i++)
    ans = (((arr[i] * ans)) / (gcd(arr[i], ans)));
  return ans;
}
void factor(vector<pair<long long, long long> > &v, long long x) {
  long long y = x;
  for (long long i = 2; i * i <= y; i++) {
    if (x % i == 0) {
      long long c = 0;
      while (x % i == 0) {
        c++;
        x = x / i;
      }
      v.push_back(make_pair(i, c));
    }
  }
  if (x != 1) v.push_back(make_pair(x, 1));
}
void solve() {
  long long n;
  cin >> n;
  string s;
  cin >> s;
  stack<long long> st;
  for (long long i = 0; i < n; i++) {
    if (s[i] == ')') {
      if (!st.empty()) st.pop();
    } else {
      st.push(s[i]);
    }
  }
  cout << st.size() << endl;
}
signed main() {
  long long tt;
  cin >> tt;
  while (tt--) {
    solve();
  }
}
