#include <cstring>
#include <deque>
#include <iostream>

using namespace std;

int main() {

	int n;

	cin >> n;

	while(n) {
		int o=0, s=0;
			char c[8];
		deque<int> b;
		while(o!=3) {
			cin >> c;
			if((strstr(c, "HIT")!=NULL)) {
				b.push_back(1);
				if(b.size()==4) {
					s++;
					b.pop_back();
				}
			}
			else if((strstr(c, "HOMERUN")!=NULL)) {
				s+=1+b.size();
				b.clear();
			}
			else if((strstr(c, "OUT")!=NULL)) {
				o++;
			}
		}
		cout << s << endl;
		n--;
	}

	return 0;

}