#include <bits/stdc++.h>
const int maxnnn = 0x3f3f3f3f;
const int oo = 1e9 + 9;
const long long inf = 1e18 + 18;
using namespace std;
long long read() {
  long long first = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    first = first * 10 + ch - '0';
    ch = getchar();
  }
  return first * f;
}
int ans;
int cot;
int main() {
  int t = read();
  while (t--) {
    int n = read();
    string s;
    cin >> s;
    ans = 0;
    cot = 0;
    for (char c : s) {
      if (c == '(')
        cot++;
      else
        cot--;
      ans = min(ans, cot);
    }
    cout << -ans << endl;
  }
}
