#define _CRT_SECURE_NO_WARNINGS

#include<fstream>
#include<iostream>
#include<string>
#include<iomanip>
#include<list>
#include<math.h>
#include<stack>
#include<queue>
#include<vector>
#include<algorithm>
#include<utility>

using namespace std;

int main(){
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		int o = 7;
		int point = 0;
		int stt = 0;
		while (o > 0){
			string s;
			cin >> s;
			if (s.compare("HIT") == 0) {
				if (stt & 4) {
					point++;
				}
				stt = (stt << 1) | 1;
			} else if (s.compare("HOMERUN") == 0) {
				while (stt > 0) {
					point++;
					stt = stt >> 1;
				}
				point++;
			} else if (s.compare("OUT") == 0) {
				o = o >> 1;
			}
		}
		cout << point << endl;
	}
	return 0;
}