#define _USE_MATH_DEFINES
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <ctime>
#include <cassert>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <list>
#include <iomanip>
#include <iterator>

using namespace std;

typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
 
int main(){
	int n; cin>>n;
	while(n--){
		int c = 0,hit = 0,p = 0;
		while(c != 3){
			string s; cin>>s;
			if(s == "HIT"){
				if(hit == 3) p++;
				else hit++;
			} else if(s == "OUT"){
				c++;
			} else {
				p += hit + 1;
				hit = 0;
			}
		}
		cout << p << endl;
	}
    return 0;
}