#include <bits/stdc++.h>
using namespace std;
int main() {
  long int t, n, a, b, x, y, i, j;
  cin >> t;
  while (t--) {
    string s;
    cin >> n;
    cin >> s;
    x = 0;
    y = 0;
    for (i = 0; i <= n; i++) {
      if (s[i] == '(' && s[i + 1] == ')') {
        i++;
        y = 1;
      } else if (s[i] == '(') {
        x++;
      } else if (s[i] == ')' && y && x) {
        x--;
      }
    }
    cout << x << endl;
  }
}
