#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int i, t, n, count = 0, c = 0;
  string br_kt;
  cin >> t;
  while (t--) {
    count = 0;
    c = 0;
    cin >> n;
    cin >> br_kt;
    i = 0;
    while (i < n) {
      while ((br_kt[i] == '(') && (i < n)) {
        count++;
        i++;
      }
      while ((br_kt[i] == ')') && (i < n)) {
        count--;
        i++;
      }
      if (count < 0) {
        c += abs(count);
        count = 0;
      }
    }
    cout << c << endl;
  }
  return 0;
}
