#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
using namespace std;
typedef pair<int,int> P;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 2000000000
#define EQ(a,b) (abs((a)-(b))<EPS)
vector<string> v;
int main()
{
	int n;
	cin >> n;
	for(int i=0;i<n;i++)
	{
		v.clear();
		int out=0;
		while(1)
		{
			string s;
			cin >> s;
			if(s=="OUT")
			{
				out++;
			}
			else
			{
				v.pb(s);
			}
			if(out==3)break;
		}
		int point=0,runner=0,f=0,s=0,t=0;
		for(int j=0;j<v.size();j++)
		{
			if(v[j]=="HIT")
			{
				if(t)
				{
					point++;
					runner--;
				}
				t=s;
				s=f;
				f=1;
				runner++;
			}
			else
			{
				f=0;s=0;t=0;
				point+=(runner+1);
				runner=0;
			}
		}
		cout << point << endl;
	}
	return 0;
}