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

int main(){
    int n, out,tmp, runner, score;
    string str;

    cin >> tmp;
    n = tmp;
    cin.get();
    while (n--){
	out = runner = score = 0;
	while (out!=3){
	    getline(cin, str);
	    if (str == "HIT"){
		runner++;
		if (runner == 4){
		    runner--;
		    score++;
		}
	    }
	    else if (str == "HOMERUN"){
		score += runner += 1;
		runner = 0;
	    } else if (str == "OUT") out++;
	}
	cout << score << endl;
    }
}