#include<iostream>
#include<string>
using namespace std;

void countHR();
void move(string str);

int mask = (1 << 4) - 1, pointMask = (1 << 4), now = 1, outCnt = 0, cnt = 0;

int main(){
    int n;
    cin >>n;
    for(int i = 0; i < n; i++){
        now = 1; outCnt = 0; cnt = 0;
        while(outCnt < 3){
            string str;
            cin >>str;
            move(str);
        }
        cout <<cnt <<endl;
    }
    return 0;
}

void move(string str){
    if(str == "HIT"){
        now = (now << 1) + 1;
        if((now & pointMask) != 0){
            cnt++;
            now = (now & mask);
        }
    } else if(str == "HOMERUN"){
        countHR();
    } else if(str == "OUT"){
        outCnt++;
    }
}

void countHR(){
    for(int countMask = 1; countMask < 16; countMask = (countMask << 1)){
        if((now & countMask) != 0){
            cnt++;
        }
    }
    now = 1;
}