//第二题测试用例过,提交通过 0%。有没有大佬帮看一下问题在哪里?谢过!

#include <iostream>
#include <cstdio>
#include<string>
using namespace std;


int process(string s) {     int count = 0;     bool flag = false;     for (int i = 0; i < s.size(); i++) {         if (s[i] == ')')             flag = false;         if (s[i] == '(')             flag = true;         if (flag==false&&(s[i] >= 'a'&&s[i] <= 'z') || (s[i] >= 'A'&&s[i] <= 'Z')) {             count++;         }     }     return count;
}

int main() {     int T;     cin >> T;     for (int i = 0; i < T; i++) {         int N;         cin >> N;         int count = 0;         string s;         char c = getchar();         for (int j = 0; j < N; j++) {             getline(cin, s);             count+=process(s);             if (s[0] == '+')                 count++;         }         cout << count<<endl;     }     return 0;
}