module AOJ_Volume0103;

import std.stdio,std.string,std.conv;

int main()
{
	int n = readln.chomp.to!int;
	while(n--)
	{
		int _out = 0;
		int home[4];
		foreach(i;0..4) home[i] = 0;

		while(_out != 3)
		{
			string s = readln.chomp;

			if(s == "OUT")
			{
				_out++;
			}
			else if(s == "HIT")
			{
				if(home[2] == 1)
				{
					home[2]--;
					home[3]++;
				}
				if(home[1] == 1)
				{
					home[1]--;
					home[2]++;
				}
				if(home[0] == 1)
				{
					home[0]--;
					home[1]++;
				}
				
				home[0]++;
			}
			else if(s == "HOMERUN")
			{
				foreach(i;0..3)
				{
					if(home[i] == 1)
					{
						home[i]--;
						home[3]++;
					}
				}
				home[3]++;
			}
		}
		home[3].writeln;
	}
	return 0;
}