#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include<iomanip>
#include <fstream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <assert.h>

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  FOR(i,0,n)
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define ALL(s) (s).begin(),(s).end()
#define ITE(c) typeof((c).begin())

#define clr(a) memset((a),0,sizeof(a))
#define nclr(a) memset((a),-1,sizeof(a))
#define pb push_back
#define INRANGE(x,s,e) ((s)<=(x) && (x)<(e))
#define MP(a,b) make_pair((a),(b))

using namespace std;

int main(){
	int n;
	cin>>n;
	rep(I,n){
		int no=0, po=0;
		int base[3]={0,0,0};
		while(no<3){
			string cmd;
			cin>>cmd;
			if(cmd=="HIT"){
				if(base[2]) po++;
				for(int i=2;i>0;--i){
					base[i]=base[i-1];
				}
				base[0]=1;
			}else if(cmd=="OUT"){
				no++;
			}else if(cmd=="HOMERUN"){
				int co=0;
				rep(i,3){
					if(base[i]){
						co++;
						base[i]=0;
					}
				}
				po+=co+1;
			}
		}
		cout<<po<<endl;
	}
	return 0;
}