#include <stdio.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
using namespace std;

int base[3];
int out = 0;
int score = 0;
int n;
string event[100];
int eventnum = 0;
int a = 0;

void Hit()
{
	base[2] = 0;
	if (base[1] == 1) base[2] = 1;
	if (base[0] == 1) base[1] = 1;
	base[0] = 1;
}

void Homerun()
{
	for (int j = 0; j < 3; j++)	{
		base[j] = 0;
	}
}

int main()
{
	cin >> n;
	for (int i = 0; i < 3 * n; i++)	{
		while (true) {
			cin >> event[a];
			a++;
			eventnum++;
			if (event[a - 1] == "OUT") break;
		}
	}

	for (int i = 0; i < eventnum; i++) {
		if (event[i] == "HIT") {
			if (base[2] == 1) score += 1;
			Hit();
		}
		else if (event[i] == "HOMERUN")	{
			score += (base[0] + base[1] + base[2] + 1);
			Homerun();
		}
		else {
			out++;
			if (out == 3) {
				cout << score << endl;
				for (int j = 0; j < 3; j++) base[j] = 0;
				score = out = 0;
			}
		}
	}
}