/*
	0103:Baseball Simulation
*/
#include	<iostream>
#include	<string>

using namespace std;

int main(void) {
	int d;
	
	cin >> d;
	
	while(d-- > 0) {
		int point = 0, outcount = 0;
		int firstBase = 0, secondBase = 0, thirdBase = 0;
		string event;
		while(outcount < 3) {
			cin >> event;
			if(event == "OUT") {
				outcount++;
			} else if(event == "HOMERUN") {
				point += firstBase + secondBase + thirdBase + 1;
				firstBase = 0;
				secondBase = 0;
				thirdBase = 0;
			} else {
				point += thirdBase;
				thirdBase = secondBase;
				secondBase = firstBase;
				firstBase = 1;
			}
		}
		cout << point << endl;
	}
	
	return 0;
}