#include <bits/stdc++.h>
using namespace std;
long long n, k, i, sum, m, counto, countc, flag, flagf, total, x, y;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int testcase;
  cin >> testcase;
  vector<long long> v1;
  vector<long long> v2;
  while (testcase--) {
    countc = 0;
    counto = 0;
    string s;
    total = 0;
    flag = 0;
    flagf = 0;
    sum = 0;
    cin >> n;
    cin >> s;
    for (i = 0; i < n; i++) {
      if (s[i] == '(') {
        counto++;
      } else {
        if (counto > 0) {
          counto--;
        } else {
          countc++;
        }
      }
    }
    cout << countc << "\n";
    v1.clear();
    v2.clear();
  }
  return 0;
}
