#include <algorithm>
#include <cmath>
#include <ctime>
#include <climits>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>
#include <cstring>
#include <tuple>
#include <bitset>
#include <unordered_map>

using namespace std;

int main() {
    int n;
    cin >> n;
    for (int i=0; i<n; ++i) {
        vector<int> base(3, 0);
        string event;
        int score = 0, out = 0;
        while (cin >> event) {
            if (event == "HIT") {
                score += base[2];
                base[2] = base[1];
                base[1] = base[0];
                base[0] = 1;
            } else if (event == "OUT") {
                out ++;
                if (3 <= out) break;
            } else if (event == "HOMERUN") {
                score += base[2] + base[1] + base[0] + 1;
                fill(base.begin(), base.end(), 0);
            }
        }
        cout << score << endl;
    }

    return 0;
}