#include <iostream>
using namespace std;


int main() {
    int N;
    cin >> N;

    string temp; getline(cin, temp);

    for (int n = 0; n != N; ++n) {
        int bases[3] = {0};
        string event;
        int runs = 0, outs = 0;
        
        while (cin >> event) {
            if (event == "HIT") {
                if (bases[2] == 1) {
                    runs++;
                    bases[2] == 0;
                }
                if (bases[1] == 1) {
                    bases[1] = 0;
                    bases[2] = 1;
                }
                if (bases[0] == 1) {
                    bases[0] = 0;
                    bases[1] = 1;
                }
                bases[0] = 1;
            }
            if (event == "HOMERUN") {
                for (int i = 0; i != 3; ++i) {
                    if (bases[i] == 1) {
                        runs++;
                        bases[i] = 0;
                    }
                }
                runs++;
            }
            if (event == "OUT") {
                outs++;
                if (outs == 3) {
                    break;
                }
            }
        }
        cout << runs << endl;
    }
}