#include <bits/stdc++.h>
int main() {
  int t, n, i, j, k, l, count_open, count_close, count;
  char s[55], a, b;
  scanf("%d\n", &t);
  while (t--) {
    scanf("%d %s", &n, s);
    count_open = 0;
    count_close = 0;
    count = 0;
    for (i = 0; i < n; i++) {
      if (s[i] == '(') {
        count_open++;
      } else if (s[i] == ')') {
        count_close++;
      }
      if (count_close > count_open) {
        count++;
        count_close--;
      }
    }
    printf("%d\n", count);
    for (i = 0; i < 52; i++) {
      s[i] = 'a';
    }
  }
  return 0;
}
