#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int t;
  cin >> t;
  while (t--) {
    long long int n;
    cin >> n;
    string s;
    cin >> s;
    long long int a, m = 0, c = 0;
    if (s[0] == '(') m += 1;
    for (long long int i = 1; i < n; i++) {
      if (s[i] == '(')
        m += 1;
      else
        m -= 1;
      if (m < 0) {
        c++;
        m += 1;
      }
    }
    if (s[0] == ')') c++;
    cout << c << endl;
  }
  return 0;
}
