#include <cstdio>
#include <string>
using namespace std;

int main(void)
{
	int n;

	scanf("%d", &n);
	while(n-- > 0){
		int base[3] = {0};
		int score = 0;
		char s[10];
		int out = 0;
		while(out < 3){
			scanf("%s", s);
			string str = s;
			if(str == "HIT"){
				if(base[2] == 1) score++;
				base[2] = base[1];
				base[1] = base[0];
				base[0] = 1;
			}
			else if(str == "HOMERUN"){
				score += base[0];
				score += base[1];
				score += base[2];
				score++;
				base[0] = base[1] = base[2] = 0;
			}
			else {
				out++;
			}
		}
		printf("%d\n", score);
	}
	
	return(0);
}
#include<iostream>
#include<string>

using namespace std;

int main()
{
	string str;
	int n;
	int E=0,out=0,score=0,base=0;
	
	cin >> n ;
	for(;;)
	{
		if(E==n)
			break;
		cin >> str ;
		if(str=="OUT")
		{
			out++;
		}
		else if(str=="HIT")
		{
			base++;
			if(base==4)
			{
				score++;
				base--;
			}
		}
		else
		{
			score+=base+1;
			base=0;
		}
		
		if(out==3)
		{
			cout << score << endl;
			out=base=score=0;
			E++;
		}
	}
}