#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  for (int mi = 0; mi < t; mi++) {
    int n;
    cin >> n;
    string s;
    cin >> s;
    int x = 0;
    int brojac = 0;
    for (int i = 0; i < s.size() - 1; i++) {
      if (s[i] == '(') {
        x++;
      } else {
        x--;
        if (x < 0) {
          brojac++;
          x = 0;
        }
      }
    }
    cout << brojac << endl;
  }
}
