// #define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <locale>
#include <cctype>
#include <sstream>
using namespace std;

typedef long long LL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef map<int, int> MAPII;
typedef vector<pair<int, int> > VPII;
typedef multimap<int, string, greater<int> > MuMIS;

#define MP make_pair
#define fastIO	cin.tie(0); ios::sync_with_stdio(false);
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
//for gcc (未test)
// #define FOREACH_IT(it,c)	for(typeof(c)::iterator it=(c).begin(); it!=(c).end(); ++it)
//for Visual Studio
#define foreach_it(type,it,c) for(type::iterator it=c.begin(), c_end=c.end(); it!=c_end; ++it)

// ------------------- include, typedef, define END. -------------------

int Hit(int *rui){
	rui[0]++;
	// 塁を進める
	FOR(i, 1, 4){
		if (rui[i - 1]==2){
			rui[i]++;
			rui[i - 1] = 1;
		}
	}
	if (rui[3]!=0){
		rui[3] = 0;
		return 1;
	}
	return 0;
}

int Homerun(int *rui){
	int ret = 1;
	FOR(i, 0, 4)
		if (rui[i])
			ret++;
	return ret;
}

int main(){
	fastIO;
	int n, outCount = 0, tokuten = 0;
	string in;
	// rui[0]〜rui[2] = 1塁〜3塁, rui[3] = 本塁
	// 各値はその塁にいる人数(0〜2)
	int rui[4] = {};
	cin >> n;
	while (cin >> in){
		if (in == "OUT")
			outCount++;
		if (outCount < 3){
			if (in == "HIT"){
				tokuten += Hit(rui);
			}
			else if (in == "HOMERUN"){
				tokuten += Homerun(rui);
				FOR(i, 0, 4)	rui[i] = 0;
			}
		}
		else{
			cout << tokuten << endl;
			FOR(i, 0, 4)	rui[i] = 0;
			tokuten = 0;
			outCount = 0;
		}
	}
	return 0;
}
#include <iostream>
#include <string>

class Baseball{
private:
	int point;
	int out_count;
	int runner;
public:
	Baseball();
	void singleHit();
	void homerun();
	void out();
	void new_inning();
	int get_out_count();
	int get_point();
	~Baseball() = default;
};

Baseball::Baseball(){
	new_inning();
}

void Baseball::singleHit(){
	if(runner < 3){
		++runner;
	}
	else if(runner == 3){
		++point;
	}
}

void Baseball::homerun(){
	point += runner + 1;
	runner = 0;

}

void Baseball::out(){
	++out_count;
}

void Baseball::new_inning(){
	point = 0;
	out_count = 0;
	runner = 0;
}

int Baseball::get_out_count(){
	return out_count;
}

int Baseball::get_point(){
	return point;
}

int main(){
	int num;
	std::cin >> num; //data set number
	Baseball baseball;
	std::string event;
	
	for(int i=0; i<num; ++i){
		baseball.new_inning();
		
		while(baseball.get_out_count() < 3){
			std::cin >> event;
			
			if(event == "HIT"){
				baseball.singleHit();
			}
			else if(event == "HOMERUN"){
				baseball.homerun();
			}
			else if(event == "OUT"){
				baseball.out();
			}
		}
		//output
		std::cout << baseball.get_point() << std::endl;
	}

}