#include <bits/stdc++.h>
using namespace std;
int read(int &x) { return scanf("%d", &x); }
int read(int &x, int &y) { return scanf("%d%d", &x, &y); }
int read(int &x, int &y, int &z) { return scanf("%d%d%d", &x, &y, &z); }
int read(long long &x) { return scanf("%lld", &x); }
int read(long long &x, long long &y) { return scanf("%lld%lld", &x, &y); }
int read(double &x) { return scanf("%lf", &x); }
char buff[2000010];
int read(string &s) {
  int r = scanf("%s", buff);
  s = buff;
  return r;
}
using namespace std;
int main() {
  int TC;
  read(TC);
  while (TC-- > 0) {
    int n;
    read(n);
    string s;
    read(s);
    while (s.find("()") != string::npos) {
      int p = s.find("()");
      s = s.erase(p, 2);
    }
    cout << s.size() / 2 << endl;
  }
}
