#include <stdio.h>
#include <string.h>
 
int main(void)
{
    int base[3] = {0};
    char happend[50];
    int score, counts, n, i, j;
 
    scanf("%d\n", &n);
     
 
    for (i = 0; i < n; i++)
    {
        counts = 0;
        score = 0;
 
        while (counts != 3)
        {
            gets(happend);
 
            if (strcmp(happend, "HIT") == 0)
            {
                if (base[2] == 1)
                {
                    score++;
                    base[2] = 0;
                }
                if (base[1] == 1)
                {
                    base[2]++;
                    base[1] = 0;
                }
                if (base[0] == 1)
                {
                    base[1]++;
                    base[0] = 0;
                }
                base[0]++;
            }
            else if (strcmp(happend, "HOMERUN") == 0)
            {
                for (j = 0; j < 3; j++)
                    if (base[j] == 1)
                    {
                        base[j] = 0;
                        score++;
                    }
                score++;
            }
            else if (strcmp(happend, "OUT") == 0)
                counts++;
        }
 
        base[0] = 0;
        base[1] = 0;
        base[2] = 0;
 
        printf("%d\n", score);
    }
 
    return 0;
}