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