var print = console.log;

function read_input(_input) {
    var lines = _input.split("\n");
    return function () {
        return lines.shift();
    };
}



// input?????\??????????????¨????????\???
function Main(_input) {
    var input = read_input(_input); // input = ?????????????????¢??°
    var N = input() - 0;
    for (var i = 0; i < N; i++) {
        var out = 0;
        var runner = 0;
        var pt = 0;
        while (out < 3) {
            var v = input();
            if (v === 'HIT') {
                runner++;
                if (runner === 4) {
                    pt++;
                    runner--;
                }
            } else if (v === 'HOMERUN') {
                pt += runner + 1;
                runner = 0;
            } else {
                out++;
            }
        }
        print(pt);
    }

}

//*???????????\????????¨??????????????§????????????????¨??????\????????????????????????????????????Main????????????????????????
 Main(require("fs").readFileSync("/dev/stdin", "utf8"));
//Main(require("fs").readFileSync("input.txt", "utf8"));