#include <iostream>

using namespace std;

int solve()
{
    string inp;
    int out_cnt = 0;
    int score = 0;
    bool base[3];

    for (int i = 0; i < 3; i++)
        base[i] = false;

    while (out_cnt < 3) {
        cin >> inp;

        if (inp == "OUT") 
            out_cnt++;
        else if (inp == "HIT") {
            if (base[2])
                score++;
            base[2] = base[1];
            base[1] = base[0];
            base[0] = true;
        }
        else if (inp == "HOMERUN") {
            for (int i = 0; i < 3; i++) {
                if (base[i])
                    score++;
                base[i] = false;
            }
            score++;
        }
    }
    return score;
}

int main()
{
    int n;

    cin >> n;
    while (n--) 
        cout << solve() << endl;

    return 0;
}