#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
using namespace std;
static const double EPS = 1e-5;
typedef long long ll;
typedef pair<int,int> pint;
#define rep(i,n) for(int i=0;i<n;i++)
#define F first
#define S second
int dx[]={1,-1,0,0},dy[]={0,0,1,-1};

int main(){
	int n;
	cin>>n;
	rep(i,n){
		string str;
		int out=0;
		int rui=0;
		int score=0;
		for(;out<3;){
			cin>>str;
			if(str=="HIT"){
				if(rui==3)score++;
				else rui++;
			}
			if(str=="HOMERUN"){
				score+=rui+1;
				rui=0;
			}
			if(str=="OUT"){
				out++;
			}
		}
		cout<<score<<endl;
	}
	return 0;
}

#include <iostream>
#include <string>

class Baseball{
public:
    Baseball();
    void init();
    int getPoint();
    void hit();
    void homerun();
    // @return false - the inning ends.
    bool out();
    
private:
    int point;
    unsigned int outs;
    bool base[3];
};

Baseball::Baseball(){
    init();
}

void Baseball::init(){
    point = 0;
    outs = 0;
    for (int i=0; i<3; ++i) {
        base[i] = false;
    }
}

inline int Baseball::getPoint(){
    return point;
}

void Baseball::hit(){
    if (base[2]) {
        ++point;
    }
    for (int i=2; i>0; --i) {
        base[i] = base[i-1];
    }
    base[0] = true;
}

void Baseball::homerun(){
    ++point;    // batter's point
    // runner's point
    for (int i=0; i<3; ++i) {
        if (base[i]) {
            ++point;
        }
    }
    
    for (int i=0; i<3; ++i) {
        base[i] = false;
    }
}

bool Baseball::out(){
    ++outs;
    if (outs > 2) {
        return false;
    }else{
        return true;
    }
}


int main(){
    int n;  // number of data sets
    
    std::cin >> n;
    
    for (int i=0; i<n; ++i) {
        Baseball inning;
        std::string str;
        
        while (true) {
            std::getline(std::cin,str);
            if (str=="HIT"){
                inning.hit();
            }
            else if (str=="HOMERUN"){
                inning.homerun();
                
            }
            else if (str=="OUT"){
                if (!inning.out()) {
                    break;
                }
            }
        }
        
        // output
        std::cout << inning.getPoint() << std::endl;
    }
    
    return 0;
}