#include <stdio.h>
#include <string.h>

#define HIT 1
#define HR 2
#define OUT 3

int main(void){
    int outCnt, pt;
    int runner; // use bits
    char event[8];
    int eventID;
    int n;
    bool endInning;
    
    scanf("%d", &n);    
    for (int i=0; i<n; i++){
        endInning = false;
        outCnt = runner = pt = 0;
        while (!endInning){
            scanf("%s", event);
            if (event[0]=='O') eventID=OUT;
            else if (event[1]=='I') eventID=HIT;
            else eventID=HR;
            switch (eventID){
            case HIT:
                if (runner & 0x4) pt++;
                runner = (runner<<1) & 0x7;
                runner |= 0x1;
                break;
            case HR:
                pt++;
                if (runner & 0x4) pt++;
                if (runner & 0x2) pt++;
                if (runner & 0x1) pt++;
                runner = 0;
                break;
            case OUT:
                if (++outCnt == 3) endInning = true;
                break;
            }
        }
        printf("%d\n",pt);
    }
    
    return 0;
}
#include <iostream>
#include <string>

using namespace std;

int main() {
	int point = 0, hits = 0, out = 0;
	int n; cin >> n;
	
	int i = 0;
	while (i < n) {
		string s; cin >> s;
		if (s == "HIT") {
			hits++;
			if (hits == 4) {
				point++;
				hits--;
			}
		}
		if (s == "OUT") {
			out++;
			if (out == 3) {
				hits = 0;
				out = 0;
				cout << point << endl;
				point = 0;
				i++;
			}
		}
		if (s == "HOMERUN") {
			point += hits + 1;
			hits = 0;
		}
	}
	
	return 0;
}