#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n, as = 0, a = 0, b = -1, ct = 0, c1 = 0, c2 = 0;
    cin >> n;
    string s;
    cin >> s;
    stack<int> st;
    queue<int> qq;
    for (int i = 0; i < n; i++) {
      if (s[i] == '(')
        st.push(i);
      else if (s[i] == ')') {
        if (!st.empty()) {
          st.pop();
        } else
          ct++;
      }
    }
    int x = min((int)st.size(), ct);
    cout << x << endl;
  }
}
