import std.stdio;
import std.algorithm;
import std.string;
import std.functional;
import std.array;
import std.conv;
import std.math;
import std.typecons;
import std.regex;
import std.range;

void main(){

    int n = readln().chomp().to!int;
    for(int i=0;i<n;i++){
	int point,o,r;
	while(true){
	    string s = readln().chomp();
	    if(s == "HIT"){
		r = 2 * r + 1;
		if(r & (1<<3)){
		    r ^= 1 << 3;
		    point++;
		}
	    }else if(s == "OUT"){
		o++;
		if(o == 3) break;
	    }else if(s == "HOMERUN"){
		point += 1 + (r & 1) + (r & 2)/2 + (r & 4)/4;
		r = 0;
	    }
	}
	writeln(point);
    }

}