#include <bits/stdc++.h>
using namespace std;
#define FOR(i,k,n) for(int i = (k); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define INF 1145141919
#define MOD 1000000007
#define ALL(a) begin((a)),end((a))
#define MS(m,v) memset(m,v,sizeof(m))
#define D10  fixed<<setprecision(10)
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> P;
typedef long long ll;
struct edge
{
	int from, to, cost;
	bool operator < (const edge& e) const { return cost < e.cost; }
	bool operator >(const edge& e) const { return cost > e.cost; }
};
typedef vector<edge> edges;
///*************************************************************************************///
///*************************************************************************************///
///*************************************************************************************///


int main()
{
	int n;
	cin >> n;
	REP(x, n)
	{
		string s;
		int cntout = 0;
		int run = 0;
		int score = 0;
		while (cin >> s)
		{
			if (s == "OUT") cntout++;
			if (cntout == 3)
			{
				cout << score << endl;
				break;
			}
			if (s == "HIT")
			{
				run <<= 1;
				run += 1;
				if (run >= 8)
				{
					score++;
					run %= 8;
				}
			}
			if (s == "HOMERUN")
			{
				score++;
				while (run > 0)
				{
					if (run & 1) score++;
					run >>= 1;
				}
			}
		}
	}
	return 0;
}