#include <iostream>
#include <string>
 
class Baseball
{
    u_int runner, out, point;
     
public:
    Baseball();
    ~Baseball(){}
         
    u_int get_out() const {return out;}
    u_int get_point() const {return point;}
    
    void game();
    void event_hit();
    void event_homerun();
    void event_out();
     
private:
    void set_runner(const u_int r) {runner = r;}
    void inc_runner() {++runner;}
    void inc_out() {++out;}
    void add_point(const u_int p) {point += p;}
};
 
Baseball::Baseball()
{
    runner = 0;
    out = 0;
    point = 0;
}

void Baseball::game()
{
    std::string event;
    while(get_out() != 3){
        std::cin >> event;
        if(event == "HIT"){
            event_hit();
        }
        else if(event == "HOMERUN"){
            event_homerun();
        }
        else{
            event_out();
        }
    }
} 

void Baseball::event_hit()
{
    if(get_runner() == 3){
        add_point(1);
    }
    else{
        inc_runner();
    }   
}
 
void Baseball::event_homerun()
{
    add_point(1 + get_runner());
    set_runner(0);
}
 
void Baseball::event_out()
{
    inc_out();
}
 
int main()
{
    u_int inning;
    std::cin >> inning;
     
    for(u_int i = 0; i < inning; ++i){
        Baseball b_ball;
        b_ball.game();
        std::cout << b_ball.get_point() << std::endl;
    }
 
    return 0;
}