#include<iostream>
#include<string>

using namespace std;

int main() {

	int N;
	cin >> N;

	for (int i = 0; i < N; i++) {

		int out = 0, point = 0, a[4] = {};
		string event;

		while (out < 3) {
			cin >> event;

			if (event == "HIT") {
				a[3] = a[2];
				a[2] = a[1];
				a[1] = a[0];
				a[0] = 1;
				if (a[3] == 1) {
					point++;
					a[3] = 0;
				}
			}
			if (event == "HOMERUN") {
				for (int j = 0; j < 3; j++) {
					if (a[j] == 1) {
						point++;
					}
					a[j] = 0;
				}
				point++;
			}
			if (event == "OUT") {
				out++;
			}
		}
		cout << point << endl;
	}

	return 0;
}
