#include <bits/stdc++.h>
const long long int mod = 1e9 + 7;
using namespace std;
bool prime(long long int n) {
  if (n <= 1) return false;
  if (n <= 3) return true;
  if (n % 2 == 0 || n % 3 == 0) return false;
  for (long long int i = 5; i * i <= n; i = i + 6)
    if (n % i == 0 || n % (i + 2) == 0) return false;
  return true;
}
bool isPowerOfTwo(long long int n) {
  if (n == 0) return false;
  return (ceil(log2(n)) == floor(log2(n)));
}
void SieveOfEratosthenes(long long int n) {
  bool prime[n + 1];
  memset(prime, true, sizeof(prime));
  for (long long int p = 2; p * p <= n; p++) {
    if (prime[p] == true) {
      for (long long int i = p * p; i <= n; i += p) prime[i] = false;
    }
  }
  for (long long int p = 2; p <= n; p++)
    if (prime[p]) cout << p << " ";
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ;
  long long int x, y, n, t;
  cin >> t;
  while (t--) {
    vector<char> s;
    cin >> n;
    char c;
    for (long long int i = 0; i < n; i++) {
      cin >> c;
      if (i) {
        if (c == ')') {
          if (s.back() == '(')
            s.pop_back();
          else
            s.push_back(c);
        } else
          s.push_back(c);
      } else
        s.push_back(c);
    }
    long long int d = s.size() / 2;
    cout << d << '\n';
  }
  return 0;
}
