#include <iostream>
#include <vector>
#include <string>

std::vector<unsigned int> res;

void solve() {
    int out=0, score=0;
    int base[4] = { 0 }; // base[0] : first
                         // base[1] : second
                         // base[2] : third
                         // base[3] : home
    std::string event;
    while (out < 3) {
        std::cin >> event;
        if (event == "OUT") {
            out++;
        } else if (event == "HOMERUN") {
            base[3] = 1;
            for (int i=0; i<4; i++) {
                score += base[i];
                base[i] = 0;
            }
        } else { // event == "HIT"
            int run=base[0];
            base[0] = 1;
            for (int i=1; i<4; i++) {
                std::swap(run, base[i]);
            }
            if (base[3] != 0) {
                score++;
                base[3] = 0;
            }
        }
    }
    std::cout << score << std::endl;
}

int main() {
    int n;
    std::cin >> n;
    for (int i=0; i<n; i++) {
        solve();
    }
}

