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

int base[3];
int point = 0;
int out = 0;
int n;

//イニング終わり
void reset_base() {
	for (int i = 0; i < 3; ++i) {
		base[i] = 0;
	}
}

//シングルヒット
void Single_hit() {
	point += base[2];
	base[2] = base[1];
	base[1] = base[0];
	base[0] = 1;
}

//ホームラン
void HomeRun() {
	for (int i = 0; i < 2; ++i) {
		point += base[i];
		base[i] = 0;
	}
	++point;
}

void Out() {
	++out;
	if (out == 3) {
		reset_base();
		out = 0;
		cout << point << endl;
		point = 0;
		--n;
	}
}


int main() {
	cin >> n;
	string s;
	while (n) {
		cin >> s;
		if (s == "HIT") {
			Single_hit();
		}
		else if (s == "HOMERUN") {
			HomeRun();
		}
		else if (s == "OUT") {
			Out();
		}
	}
        return 0;
}
