#include <bits/stdc++.h>
using namespace std;
int main() {
  int tes;
  cin >> tes;
  while (tes--) {
    long long int n, i, j, cnt, cnt1, mx, a = 0, r = 0;
    ;
    string ch;
    cin >> n;
    cin >> ch;
    for (i = 0; i < ch.size(); i++) {
      if (ch[i] == '(')
        a++;
      else
        a--;
      if (a < 0) {
        a = 0;
        r++;
      }
    }
    cout << r << endl;
  }
  return 0;
}
