#include <iostream>
using namespace std;
int main(void){
    int n;
    cin >> n;
    cin.ignore();
    string hit = "HIT";
    string home = "HOMERUN";
    string out = "OUT";
    string in;
    bool* runer = new bool[3];
    int point = 0;
    int outcount;
    for(int i = 0; i < n; ++i) {
        outcount = 0;
        point = 0;
        for(int j = 0; j < 3; ++j) {
            runer[j] = false;
        }
        while(1) {
            cin >> in;
            if (in.compare(hit) == 0) {
                if (runer[0] == false) {
                    runer[0] = true;
                }
		else {
                    if (runer[1] == false) {
                        runer[1] = true;
                    }
                    else {
                        if (runer[2] == false) {
                            runer[2] = true;
                        }
                        else {
                            ++point;
                        }
                    }

                }

            }
 else if (in.compare(home) == 0) {
                ++point;
                if (runer[0] == true) {
                    ++point;
                    if (runer[1] == true) {
                        ++point;
                        if (runer[2] == true) {
                            ++point;
                        }
                    }

                }

                for(int j = 0; j < 3; ++j) {
                    runer[j] = false;
                }


            }
            else if (in.compare(out) == 0) {
                ++outcount;
                if (outcount >= 3) {
                    cout << point << endl;
                    break;
        	}
            }

        }

    }
    delete [] runer;
}