#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int t;
  cin >> t;
  int n, num, ctr;
  string s;
  while (t--) {
    cin >> n >> s;
    num = 0;
    ctr = 0;
    for (char ch : s) {
      if (ch == ')') {
        num--;
        if (num < 0) ctr++, num++;
      } else
        num++;
    }
    cout << ctr << "\n";
  }
}
