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