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

int main(){
	int n;
	cin >> n;
	for(int p=0; p < n; p++){
		int score = 0, out = 0, run[5];
		string event;
		fill(run, run+5, 0);

		while(1){
			cin >> event;
			if(event == "HIT"){
				run[0] = 1;
				for(int i=3; 0 <= i; i--){
					if(run[i] == 1) swap(run[i], run[i+1]);
				}
				if(run[4] == 1){
					score++;
					run[4] = 0;
				}
			}
			if(event == "HOMERUN"){
				run[0] = 1;
				for(int i=0; i < 4; i++){
					if(run[i] == 1){
						score++;
						run[i] = 0;
					}
				}
			}
			if(event == "OUT") out++;
			if(out == 3) break;
		}
		cout << score << endl;
	}
}