#include <iostream>
#include <cstdio>

using namespace std;

int main(){
	
	int n, ans, out;
	
	string str;
	
	bool base[3];
	
	cin >> n;
	
	for(int loop = 0; loop < n; loop++){
		
		base[0] = false;
		base[1] = false;
		base[2] = false;
		
		ans = 0;
		out = 0;
		
		while(true){
			
			cin >> str;
			
			if(str == "HIT"){
				if(base[2]){
					ans++;
				}
				if(base[1]){
					base[2] = true;
				}else{
					base[2] = false;
				}
				if(base[0]){
					base[1] = true;
				}else{
					base[1] = false;
				}
				base[0] = true;
			}else if(str == "HOMERUN"){
				ans++;
				if(base[2]){
					ans++;
				}
				if(base[1]){
					ans++;
				}
				if(base[0]){
					ans++;
				}
				base[0] = false;
				base[1] = false;
				base[2] = false;
			}else if(str == "OUT"){
				out++;
			}
			if(out >= 3){
				break;
			}
		}
		printf("%d\n", ans);
	}
	
	return 0;
}
#include <iostream>
using namespace std;

int type(string s){
	if(s == "HIT")return 0;
	if(s == "OUT")return 1;
	if(s == "HOMERUN")return 2;
}
int main(){
	int n;
	string s;
	cin >> n;
	
	while(n--){
		int outCount = 0;
		int base = 0;
		int result = 0;
		while(outCount < 3){
			cin >> s;
			switch(type(s)){
			case 0:
				base <<= 1;
				base++;
				break;
			case 1:
				outCount++;
				break;
			case 2:
				result += __builtin_popcount(base)+1;
				base = 0;
				break;
			}
			if(base & 8)result++;
			base &= 7; // 0b0111
		}
		cout << result << endl;
	}
}