//有没有大佬帮看看第二题呢,只过了测试样例,提交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;
}