#include <iostream>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <string>
#include <bitset>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <sstream>
#include <fstream>
#include <string.h>

#define X first
#define Y second
#define MP make_pair
#define FOR(i, n) for(int i = 0; i < n; i++)
typedef long long ll;
using namespace std;
const int MAX = 101;

template<class T, class U>
void convert(T &t, U &u){
    stringstream ss;
    ss << t;
    ss >> u;
}

int main(){
	int n;
	cin >> n;
	while(n--){
		bool base[4];
		memset(base, false, sizeof(base));
		int out = 0, point = 0;
		while(1){
			bool base_next[4];
			memset(base_next, false, sizeof(base_next));
			string ev;
			cin >> ev;
			if(ev=="HIT"){
				FOR(i, 3){
					if(base[i]){
						base_next[i+1]=true;
						if(i+1==3) point++;
					}
				}
				base_next[0]=true;
			}else if(ev=="OUT"){
				out++;
				if(out==3) break;
				continue;
			}else{
				FOR(i, 3){
					if(base[i]) point++;
				}
				point++;
			}
			FOR(i, 4){
				base[i] = base_next[i];
			}
		}
		cout << point << endl;
	}
	return 0;
}