#include <bits/stdc++.h>
using namespace std;
long long int MAX = 9223372036854775807;
long long int MIN = -9223372036854775807;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t;
  cin >> t;
  while (t--) {
    long long int n, cnt = 0, prev = 0, ans = 0;
    cin >> n;
    string s;
    cin >> s;
    for (long long int i = 0; i < n; i++) {
      if (s[i] == '(')
        cnt++;
      else
        cnt--;
      if (cnt < 0) {
        ans++;
        cnt = 0;
      }
    }
    cout << ans << '\n';
  }
  return 0;
}
