#include <iostream>
#include <string>
using namespace std;
int main() {
    int n, o, sum;
    int f[3];
    string str;
    cin >> n;
    for (int i = 0; i < n; i++) {
        fill(f, f+3, 0);
        sum = o = 0;
        while (1) {
            cin >> str;
            if (str == "OUT") {
                o++;
                if (o == 3) break;
            }
            else if (str == "HOMERUN") {
                sum++;
                for (int i = 0; i < 3; i++) if (f[i] == 1) sum++, f[i] = 0;
            }
            else if (str == "HIT") {
                if (f[2] == 1) sum++, f[2] = 0;
                for (int i = 1; i >= 0; i--) if (f[i] == 1) swap(f[i], f[i+1]);
                f[0] = 1;
            }
        }
        cout << sum << endl;
    }
    return 0;
}

