#include <bits/stdc++.h>
using namespace std;
const int N = 200000 + 10;
long long n, m, x, y, k, a, b, st, ans, p;
long long arr[N], sumo, sumt;
void fin() {
  while (n % 2 == 0) {
    n /= 2;
    sumo++;
  }
  while (n % 3 == 0) {
    n /= 3;
    sumt++;
  }
}
void solve() {
  cin >> n;
  string s;
  cin >> s;
  int cnt = 0;
  stack<char> st;
  for (int i = 1; i < n; i++) {
    if (s[i] == '(') st.push(s[i]);
    if (s[i + 1] == ')' && !st.empty()) {
      st.pop();
      cnt++;
    }
  }
  cout << st.size();
}
int main() {
  int t = 1;
  cin >> t;
  int a = 0;
  while (t--) {
    solve();
    cout << "\n";
  }
  return 0;
}
