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