#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <stdio.h>
#include <string>
#include <string.h>
#include <queue>
#include <cmath>
#include <stack>
#include <map>
#include <vector>
#include <algorithm>

#define int64 long long int
using namespace std;

int main()
{
	int n;
	int base[3], out, point;
	string ev;

	cin >> n;
	for(int i=0; i<n; i++){
		point = 0;
		out = 0;
		base[0] = base[1] = base[2] = 0;
		while(out < 3){
			cin >> ev;
			if(ev == "OUT") out++;
			else if(ev == "HOMERUN"){
				point += base[0] + base[1] + base[2] + 1;
				base[0] = base[1] = base[2] = 0;
			} else {
				if(base[2] == 1) point++;
				base[2] = base[1];
				base[1] = base[0];
				base[0] = 1;
			}
		}
		cout << point << endl;
	}

	return 0;
}