Go: package main

import (
	"bufio"
	"fmt"
	"os"
)

var scanner = bufio.NewScanner(os.Stdin)

func main() {
	var inning int

	fmt.Scanf("%d", &inning)

	score := make([]int, inning)

	for i := 0; i < inning; i++ {
		var outCount, runnerCount int

		for scanner.Scan() {
			event := scanner.Text()

			// HIT, HOMERUN, OUT
			switch event {
			case "HIT":
				runnerCount++
				if runnerCount > 3 {
					runnerCount--
					score[i]++
				}
			case "HOMERUN":
				score[i] += runnerCount + 1
				runnerCount = 0
			case "OUT":
				outCount++
			}

			if outCount == 3 {
				break
			}
		}
	}

	for _, v := range score {
		fmt.Println(v)
	}
}

C++: //#define _GRIBCXX_DEBUG
#include <algorithm>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <iomanip>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;


// ?????¬???????????¬??????
#pragma region MACRO
#define P(x) cout << (x) << endl
#define p(x) cout << (x)
#define PED cout << "\n"
#define rep(i,n) for(int i=0; i<(int)n; ++i)
#define REP(i,x,n) for(int i=x; i<(int)n; ++i)
#define repi(i,n) for(int i=0; i<=(int)n; ++i)
#define REPI(i,x,n) for(int i=x; i<=(int)n; ++i)
#define ILP while(true)
#define FOR(i,c) for(__typeof((c).begin())!=(c).begin(); i!=(c).end(); ++i)
#define ALL(c) (c).begin(), (c).end()
#define mp make_pair
#pragma endregion

// ???
#pragma region TYPE_DEF
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<string, string> pss;
typedef pair<string, int> psi;
typedef pair<int, string> pis;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<long> vl;
typedef vector<long long> vll;
typedef vector<string> vs;
#pragma endregion

// Effective std
#pragma region ESTD
template<typename C, typename T>
constexpr int count(C& c, T t) { return count(ALL(c), t); }
template<typename C, typename F>
constexpr int count_if(C& c, F f) { return count_if(ALL(c), f); }
template<typename C, typename T>
void erase(C& c, T t) { remove(ALL(c), t), c.end(); }
template<typename C>
void remove(vector<C>& c, unsigned int index) { c.erase(c.begin()+index); }
template<typename C, typename T, typename U>
constexpr void replace(C& c, T t, U u) { replace(ALL(c), t, u); }
template<typename C, typename F, typename U>
constexpr void replace_if(C& c, F f, U u) { (ALL(c), f, u); }
template<typename C>
constexpr void reverse(C& c) { reverse(ALL(c)); }
template<typename C>
constexpr void sort(C& c) { sort(ALL(c)); }
template<typename C, typename Pred>
constexpr void sort(C& c, Pred p) { sort(ALL(c), p); }
#pragma endregion

// ?????°
#pragma region CONST_VAL
#define PI (2*acos(0.0))
#define EPS (1e-9)
#define MOD (int)(1e9+7)
#pragma endregion


int main()
{
    int n; cin >> n;
    int i=0;
    int score=0,out=0;
    vi v;
    while(i<n) {
        string s; cin >> s;
        if(s=="OUT") {
            out++;
            if(out==3) {
                P(score);
                score=0;out=0;v.clear();
                i++;
            }
        }
        if(s=="HIT") {
            if(v.size()==3) score++;
            else v.push_back(1);
        }
        if(s=="HOMERUN") {
            score+=v.size()+1;
            v.clear();
        }

    }
    return 0;
}

C++: #include <iostream>
#include <bitset>
#include <string>

int main(void) {
    u_int n;
    std::string event;

    std::cin >> n;
    for (u_int i = 0; i < n; ++i) {
        // 各ビットがそれぞれの塁のランナーの有無を表現する
        std::bitset<4> runner;
        u_int out = 0, score = 0;

        do {
            std::cin >> event;
            if ("HIT" == event) {
                runner <<= 1;   // ランナーを1つずつ進める
                runner.set(0);  // 一塁にランナーを置く
                // ホームインしたかどうか
                if (runner.test(3)) {
                    ++score;
                    runner.reset(3);
                }
            } else if ("HOMERUN" == event) {
                score += runner.count() + 1;
                runner.reset(); // ランナーをリセット
            } else if ("OUT" == event) {
                ++out;
            }
        } while (out != 3);

        std::cout << score << std::endl;
    }

    return 0;
}

C++: #include <iostream>
main(){int i,n,o,b,p;char s[9];for(std::cin>>n;n--;std::cout<<p<<std::endl)for(o=b=p=0;o<3;b&=7){std::cin>>s;if(*s==79)o++;if(s[1]==79)b=b<<4|8;if(s[1]==73)b+=b+1;for(i=8;i<128;i*=2)if(b&i)p++;}}

C++: #include<iostream>
#include<string>
using namespace std;
int main(){
	int a,b,c,d;
	int score;
	int out=0;
	int n;
	cin>>n;
	while(n--){
		score=a=b=c=d=0;
		string e;
		while(out!=3){
			cin>>e;
			if(e=="HIT"){
				d=c;c=b;b=a;a=1;
				score+=d;d=0;	
			}else if(e=="HOMERUN"){
				score += a+b+c+1;
				a=b=c=0;
			}else{
				out++;
			}
		}
		cout<<score<<endl;
	}
	return 0;
}

C++: #include<stdio.h>

int main(void)
{
  char str[16]={};
  int n;
  int score=0;
  int base=0;
  int out=0;

  scanf("%d", &n);

  for(i=0;i<n;i++)
    {
      scanf("%s", str);
      if(str[1]='I')
        if(base==3)
          score++,base=0;
        else
          base++;
      else if(str[1]='U')
        if(out==2)
          out=base=0;
        else
          out++;
      else if(str[1]='O')
	score+=base+1,base=0;
    }
  return 0;
}

C++: #include <iostream>
using namespace std;

int main()
{
	int point, base, n, out;
	char ibe[10];

	cin >> n;
	for (int k = 0; k < n; k++){
		base = point = out = 0;
		while (out != 3){
	 	 cin >> ibe;
		 if (ibe[0] == 'H' && ibe[1] == 'I' && ibe[2] == 'T'){
			 base++;
			 if (base == 4){
				 base--;
				 point++;
			 }
		 }
		 else if (ibe[0] == 'O'){
			 out++;
		 }
		 else {
			 point += base;
			 base = 0;
		 }
		 cout << base << endl;
		}
		cout << point << endl;
	}
	return (0);
}

C++: #include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
using namespace std;
int main(void){
    // Here your code !
    int n;
    cin >> n;
    vector<string> a(100);
    bool run[3]={false, false, false};
    int out=0, e=0;
    int point[n];
    int i=0;
    while(cin >> a[i]) {
        if(a[i]=="HIT") {
            if(run[2]) {
                point[e]++;
                run[2] = false;
            }
            if(run[1]) {
                run[2] = true;
                run[1] = false;
            }
            if(run[0]) {
                run[1] = true;
                run[0] = false;
            }
            run[0] = true;
        } else if(a[i]=="OUT") {
            out++;
            if(out==3) {
                out = 0;
                run[0] = false;
                run[1] = false;
                run[2] = false;
                e++;
            }
        } else {
            int k=0;
            if(run[0]) k++;
            if(run[1]) k++;
            if(run[2]) k++;
            run[0] = false;
            run[1] = false;
            run[2] = false;
            REP(i,k) {
                point[e]++;
            }
            point[e]++;
        }
        i++;
    }
    REP(i,n) {
        cout << point[i] << endl;
    }
    
}

C++: b,o,s;main(a){for(scanf("%d");~scanf("%s",&a);)a%3?a&1?++o%3?:(s=!printf("%d\n",b>3?s+b-3:s),b=0):b++:(s+=b+1,b=0);}