#include <bits/stdc++.h>
using namespace std;
long long t, n, sum, t1, ans;
string st;
int main() {
  cin >> t;
  while (t--) {
    cin >> n;
    cin >> st;
    int a = 0, b = 0;
    for (int i = 0; i < n; i++) {
      if (st[i] == '(') a++;
      if (st[i] == ')') {
        if (a)
          a--;
        else
          b++;
      }
    }
    cout << min(a, b) << "\n";
  }
}
