#include <bits/stdc++.h>
using namespace std;
const int maxx = 2e5 + 20, mod = 1e9 + 7;
int main() {
  int t;
  cin >> t;
  while (t--) {
    string s;
    int n, sum = 0, ans = 0;
    cin >> n >> s;
    for (int i = 0; i < n; i++) {
      if (s[i] == '(')
        sum++;
      else
        sum--;
      if (sum < 0) {
        while (s[i] == ')') {
          ans++;
          i++;
        }
        sum = 1;
      }
    }
    cout << ans << endl;
  }
  return 0;
}
