#include <iostream>
using namespace std;

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

    string temp; getline(cin, temp);

    for (int n = 0; n != N; ++n) {
        string event;
        int runners = 0, points = 0, out = 0;
        
        while (cin >> event && out < 3) {
            if (event == "HIT") {
                if (runners == 3) {
                    points++;
                }
                else {
                    runners++;
                }
            }
            else if (event == "HOMERUN") {
                points += runners + 1;
                runners = 0;
            }
            else if (event == "OUT") {
                out++;
            }
        }
        cout << points << endl;
    }
}