#define _CRT_SECURE_NO_WARNINGS
#include"bits/stdc++.h"
#define INF         1e9
#define EPS         1e-9
#define REP(i,n)    for(ll i=0,i##_len=(n);i<i##_len;++i)
#define REP1(i,n)   for(ll i=1,i##_len=(n);i<=i##_len;++i)
#define REPR(i,n)   for(ll i=(n)-1;i>=0;--i)
#define REPR1(i,n)  for(ll i=(n);i>0;--i)
#define REPC(i,obj) for(auto i:obj)
#define R_UP(a,b)   (((a)+(b)-1)/(b))
#define ALL(obj)    (obj).begin(),(obj).end()
#define SETP        cout << fixed << setprecision(8)
using namespace std;
using ll = long long;
template<typename T = ll>inline T in() { T x; cin >> x; return x; }

signed main()
{
	int inning = in();
	REP(i, inning) {
		bool base[3]{ false, false, false };
		int point = 0, out = 0;
		while (out < 3) {
			string str = in<string>();
			if (str == "HIT") {
				if (base[2]) {
					++point;
					base[2] = false;
				}
				if (base[1]) {
					base[2] = true;
					base[1] = false;
				}
				if (base[0]) {
					base[1] = true;
					base[0] = false;
				}
				base[0] = true;
			} else if (str == "HOMERUN") {
				REP(i, 3) {
					if (base[i]) {
						++point;
						base[i] = false;
					}
				}
				++point;
			} else if (str == "OUT") {
				if (++out == 3) {
					break;
				}
			}
		}
		cout << point << endl;
	}
}
