#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    string x;
    cin >> x;
    int temp = 0, ans = 0;
    for (int i = 0; i < n; i++) {
      if (x[i] == '(')
        temp++;
      else if (x[i] == ')')
        temp--;
      if (temp < 0) {
        ans++;
        temp = 0;
      }
    }
    cout << ans << endl;
  }
}
