#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    string s;
    int n;
    cin >> n >> s;
    int count = 0;
    int ans = 0;
    for (auto d : s) {
      if (d == '(')
        count++;
      else
        count--;
      ans = min(ans, count);
    }
    cout << -(ans) << endl;
    ans = 0;
  }
  return 0;
}
