#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    string s;
    cin >> s;
    int i = 0;
    while (s[i] != '\0') {
      if (s[i] == '(' && s[i + 1] == ')')
        s.erase(i, 2), i = 0;
      else
        i++;
    }
    cout << s.length() / 2 << endl;
  }
  return 0;
}
