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

int main() {
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		int base = 0, out = 0, point = 0;
		while (out != 3) {
			string s;
			cin >> s;
			if (s == "HIT") {
				if (base == 3) {
					point++;
				}
				else if (base < 3) {
					base++;
				}
			}
			else if (s == "HOMERUN") {
				point += base + 1;
				base = 0;
			}
			else {
				out++;
			}
		}
		cout << point << endl;
	}
}
