#include <cmath>
#include <ctime>
#include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <list>
#include <deque>
#include <stack>
#include <bitset>
#include <functional>
#include <numeric>
#include <utility>
#include <iomanip>
#include <cstdio>
#include <cctype>
#include <queue>
#include <complex>
#include <climits>

typedef long long ll;

using namespace std;

void hit(int base[], int& score){
	if(base[2] == 1){
		score++;
		base[2] = 0;
	}
	if(base[1] == 1){
		base[2] = 1, base[1] = 0;
	}
	if(base[0] == 1){
		base[1] = 1;
	}
	base[0] = 1;

	return ;
}

void homerun(int base[], int& score){
	score += base[0] + base[1] + base[2] + 1;
	base[0] = base[1] = base[2] = 0;
	return ;
}

int main(void){
	int n;
	cin >> n;

	for(int i=0; i<n; ++i){
		int score = 0, out = 0;
		int base[3] = {0};
		string s;
		while(1){
			cin >> s;
			if(s == "HIT")
				hit(base, score);
			if(s == "HOMERUN")
				homerun(base, score);
			if(s == "OUT"){
				out++;
				if(out == 3){
					cout << score << endl;
					break;
				}
			}
		}
	}


	return 0;
}