#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

int main() {
    int n;
    cin >> n;
    for (int _ = 0; _ < n; ++_) {
        int outs = 0, score = 0, a = 0, b = 0, c = 0;
        while(outs < 3){
            string s;
            cin >> s;
            if(s == "HIT"){
                score += c; c = b; b = a; a = 1;
            }else if(s == "HOMERUN"){
                score += a+b+c+1; a = b = c = 0;
            }else {
                outs++;
            }
        }
        cout << score << "\n";
    }
    return 0;
}
