#include <iostream>
#include <string>

using namespace std;

bool state[3];
int point;
int out_count;

int init() {
    point = 0;
    out_count = 0;
    for (int i = 0; i < 3; i++) 
        state[i] = false;
}

void hit() {
    if (state[2]) point++;
    if (state[1]) state[2] = true;
    if (state[0]) state[1] = true;
    state[0] = true;
}

void homerun() {
    point++;
    for (int i = 0; i < 3; i++) {
        if (state[i]) {
            point++;
            state[i] = false;
        }
    }
}

void out() {
    out_count++;
}

void solve() {
    init();
    string s;
    while (cin >> s) {
        if (s == "HIT") hit();
        else if (s == "HOMERUN") homerun();
        else if (s == "OUT") {
            out();
            if (out_count == 3) {
                cout << point << endl;
                break;
            }
        }
    }
}

int main() {
    int n; cin >> n;
    for (int i = 0; i < n; i++) {
        solve();
    }
    return 0;
}