#include <bits/stdc++.h>
using namespace std;
long long int v[200005], se[200005];
int main() {
  long long int t, n, i, j, k, l, temp, b, p, q, r, y, z, mu, add, W, m, a, x,
      c, f;
  cin >> t;
  while (t--) {
    cin >> n;
    string str;
    cin >> str;
    n = str.length();
    long long int sum = 0, ans = INT_MAX;
    for (i = 0; i < n; i++) {
      if (str[i] == ')')
        sum--;
      else
        sum++;
      ans = min(ans, sum);
    }
    cout << abs(ans) << endl;
  }
  return 0;
}
