#include <iostream>
#include <cstdlib>
#include <cstring>
using namespace std;

int PrintPoint();

int main()
{
    int i;

    cin >> i;
    for(int c=0; c < i; c++)
        PrintPoint();

    return EXIT_SUCCESS;
}

int PrintPoint()
{
    int iPoint = 0;
    int iRunner = 0;
    string sEvent;
    for(int iOutCount = 0; iOutCount < 3;)
    {
        cin >> sEvent;
        if(sEvent == "HOMERUN")
        {
            iPoint += iRunner + 1;
            iRunner = 0;
        }
        if(sEvent == "HIT")
        {
            iRunner++;
            if(iRunner > 3)
            {
                iRunner -= 1;
                iPoint++;
            }
        }
        if(sEvent == "OUT")
            iOutCount++;
    }
    cout << iPoint << endl;
    return 0;
}