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