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

int main(){
	int n;
	cin >> n;
	for(int i=0; i<n; i++){
		int hit = 0, out = 0, point = 0;
		string event;
		while( cin >> event ){
			if( event == "HIT" ){
				hit++;
				if( hit == 4 ){
					point++;
					hit--;
				}
			}else if( event == "HOMERUN" ){
				point += hit+1;
				hit = 0;
			}else if( event == "OUT" ) out++;
			
			if( out == 3 ) break;
		}
		cout << point << endl;
	}
}