#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;

#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for (int i = x; i < n; i++)
#define OP(m) cout << m << endl
typedef long long ll;
typedef unsigned long long ull;

int main()
{
    int n;
    cin >> n;

    rep(i, n)
    {
        int out_sum = 0, point = 0;
        vector<int> base(4, 0);
        string s;
        while (out_sum != 3)
        {
            cin >> s;
            if (s == "OUT")
                out_sum++;
            else if (s == "HOMERUN")
            {
                point += accumulate(ALL(base), 0) + 1;
                rep(i, 3) base[i] = 0;
            }
            else if (s == "HIT")
            {
                bool cnt[3] = {};
                rep(i, 3) if (base[i] == 1) cnt[i] = 1;
                rep(i, 4)
                {
                    if (cnt[i] == 1)
                    {
                        base[i + 1]++;
                        base[i]--;
                    }
                }
                base[0] = 1;
                if (base[3] == 1)
                {
                    point++;
                    base[3] = 0;
                }
            }
        }
        OP(point);
    }

    return 0;
}
