Go: package main

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

func main() {
	stdin := bufio.NewScanner(os.Stdin)
	stdin.Scan()
	n, _ := strconv.Atoi(stdin.Text())
	for i := 0; i < n; i++ {
		base := [3]bool{}
		score, out := 0, 0
		for stdin.Scan() {
			switch stdin.Text() {
			case "HIT":
				if base[2] { // 3塁
					score++
				}
				if base[1] { // 2塁
					base[2] = true
					base[1] = false
				}
				if base[0] { // 1塁
					base[1] = true
				}
				base[0] = true
			case "HOMERUN":
				for i := 0; i < 3; i++ {
					if base[i] {
						score++
						base[i] = false
					}
				}
				score++
			case "OUT":
				out++
			}
			if out >= 3 {
				fmt.Println(score)
				break
			}
		}
	}
}

C++: #include "bits/stdc++.h"

#define REP(i,n) for(ll i=0;i<n;++i)
#define RREP(i,n) for(ll i=n-1;i>=0;--i)
#define FOR(i,m,n) for(ll i=m;i<n;++i)
#define RFOR(i,m,n) for(ll i=n-1;i>=m;--i)
#define ALL(v) (v).begin(),(v).end()
#define PB(a) push_back(a)
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());
#define DUMP(v) REP(i, (v).size()) { cout << v[i]; if (i != v.size() - 1)cout << " "; else cout << endl; }
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

const int dx[8] = { 1,1,0,-1,-1,-1,0,1 };
const int dy[8] = { 0,1,1,1,0,-1,-1,-1 };


using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
ll max(ll a, int b) { return max(a, ll(b)); }
ll max(int a, ll b) { return max(ll(a), b); }
///(テッツセツε」ツ?、テッツスツエテッツセツεッツスツ」テッツセツづ篠エテッツスツサテッツセツεヲツクツ嘉・ツ伉嘉ッツスツ」テッツセツづ篠エテッツスツサ`)(テッツセツε」ツ?、テッツスツエテッツセツεッツスツ」テッツセツづ篠エテッツスツサテッツセツεヲツクツ嘉・ツ伉嘉ッツスツ」テッツセツづ篠エテッツスツサ`)(テッツセツε」ツ?、テッツスツエテッツセツεッツスツ」テッツセツづ篠エテッツスツサテッツセツεヲツクツ嘉・ツ伉嘉ッツスツ」テッツセツづ篠エテッツスツサ`)(テッツセツε」ツ?、テッツスツエテッツセツεッツスツ」テッツセツづ篠エテッツスツサテッツセツεヲツクツ嘉・ツ伉嘉ッツスツ」テッツセツづ篠エテッツスツサ`)(テッツセツε」ツ?、テッツスツエテッツセツεッツスツ」テッツセツづ篠エテッツスツサテッツセツεヲツクツ嘉・ツ伉嘉ッツスツ」テッツセツづ篠エテッツスツサ`)(テッツセツε」ツ?、テッツスツエテッツセツεッツスツ」テッツセツづ篠エテッツスツサテッツセツεヲツクツ嘉・ツ伉嘉ッツスツ」テッツセツづ篠エテッツスツサ`)///
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	REP(j, n) {
		int out = 0, score = 0;
		int cnt = 0;
		vi v(3, 0);
		while (out < 3) {
			string s;
			if (cin >> s)cnt++;

			if (s == "HIT") {
				RREP(i, 3) {
					if (v[i] == 1) {
						if (i == 2)score++;
						else v[i + 1]++;
						v[i]--;

					}
				}
				v[0]++;
			}
			else if (s[0] == 'O') {
				out++;
			}
			else {
				REP(i, 3) {
					if (v[i] == 1) {
						score++;
						v[i] = 0;
					}
				}
				score++;
			}
			assert(cnt <= 100);

		}
		cout << score << endl;
	}
	return 0;
}

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

int main(void)
{
  int n;
  cin >> n;
  char c[8];
  int i = 0;
  int out = 0;
  int array[3] = {};
  int score = 0;

  while(i != n){
    cin >> c;
    if(c[0] == 'H' && c[1] == 'I' && c[2] == 'T'){
      if(array[2] == 1){
	score++;
      }
      array[2] = array[1];
      array[1] = array[0];
      array[0] = 1;
    }
    if(c[0] == 'H' && c[1] == 'O' && c[2] == 'M' && c[3] == 'E' && c[4] == 'R' && c[5] == 'U' && c[6] == 'N'){
      score = score + array[0] + array[1] + array[2] + 1;
      array[0] = 0;
      array[1] = 0;
      array[2] = 0;
    }
    
    if(c[0] == 'O' && c[1] == 'U' && c[2] == 'T'){
      out++;
    }
    if(out == 3){
      cout << score << endl;
      array[0] = 0;
      array[1] = 0;
      array[2] = 0;
      score = 0;
      out = 0;
      i++;
    }
  }
  return 0;
}

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

int base;

int hit(){
	if(base==3) return 1;
	else base++;
	return 0;
}

int homerun(){
	base++;
	return base;
}

int main(){
	int inning;
	std::cin << inning;

	for(int i=0;i<inning;i++){
		int outCount=0;
		int point=0;
		string result;
		base=0;
		while(outCount<3){
			std::cin << result;

			if(result == "HIT"){
				point += hit();
			} else if(result == "HOMERUN"){
				point += homerun();
				base=0;
			} else if(result == "OUT"){
				outCount++;
			}
		}
		std::cout >> point >> std::endl;
	}

    return 0;
}

C++: #include <stdio.h>
#include <string.h>
int main(void){
	int dataset,ining;
	int i;
	int runner[3],point,out;
	char str[8];

	scanf("%d",&dataset);
	for(ining=0;ining<dataset;ining++){

		//init state variable
		for(i=0;i<3;i++){
			runner[i]=0;
		}
		point=0;
		out=0;

		//start	ining
		while(out<3){
			scanf("%s",&str[0]);

			if(strcmp(str,"HOMERUN")==0){
		                for(i=0;i<3;i++){
					point+=runner[i];
		                        runner[i]=0;
		                }
				point++;
			}

			else if(strcmp(str,"HIT")==0){
				if(runner[2]==1){
					runner[2]=0;
					point++;
				}
				if(runner[1]==1){
					runner[1]=0;
					runner[2]=1;
				}
				if(runner[0]==1){
					runner[0]=0;
					runner[1]=1;
				}
				runner[0]=1;
			}

			else if(strcmp(str,"OUT")==0){
				out++;
			}
		}

		//finish ining
		printf("%d\n",point);
	}
}

C++: #include<stdio.h>
#include<iostream>
using namespace std;
int main(void)
{
	int n,i=0,out=0,g=0;
	int cange=0,score[2]={0,0};
	char evn[100][7];
	int base[4]={0,0,0,0};
	cin >> n;
	while(n!=g){
		cin >> evn[i];
		if(evn[i][1]=='I'){
			base[3]+=base[2];
			base[2]=base[1];
			base[1]=base[0];
			base[0]=1;
		}
		if(evn[i][1]=='O'){
			base[3]+=base[2]+base[1]+base[0]+1;
			base[2]=0;
			base[1]=0;
			base[0]=0;
		}
		if(evn[i][0]=='O'){
			out++;
		}
		if(out==3){
			out=0;
			base[0]=0;
			base[1]=0;
			base[2]=0;
			if(cange==0){
				score[0]+=base[3];
				base[3]=0;
				cange=1;
				g++;
			}
			else{
				score[1]+=base[3];
				base[3]=0;
				cange=0;
				g++;
			}
		}
	}
	cout << score[0] << endl <<score[1] << endl;
return 0;
}

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

int main(){
  int n;
  string s;
  cin >> n;
  for(int i=0; i<n; i++){
    int point=0, out_count=0;
    int r[3];
    for(int i=0; i<3; i++) r[i] = 0;
    while(out_count != 3){
      cin >> s;
      if(s == "HOMERUN"){
	point++;
	for(int i=0; i<3; i++){
	  if(r[i] != 0){
	    point++;
	    r[i] = 0;
	  }
	}
      }
      if(s == "HIT"){
	r[0]++;
	if(r[0] > 1 && r[0] != 0){
	  r[0]--;
	  r[1]++;
	}
	if(r[1] > 1 && r[1] != 0){
	  r[1]--;
	  r[2]++;
	}
	if(r[2] > 1 && r[2] != 0){
	  r[2]--;
	  point++;
	}
      }
      if(s == "OUT") out_count++;
    }
    cout << point << endl;
  }
}

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

using namespace std;

int main()
{
	int n,p,c,o;
	string event;
	
	cin>>n;
	while(n>0){
		p=o=c=0;
		while(1){
			cin>>event;
			if(event=="HOMERUN"){
				p+=c+1;
				c=0;
			}
			else if(event=="OUT"){
				o+=1;
			}
			else{
				c+=1;
				if(c==4){
					c--;
					p++;
				}
			}
			if(o==3)break;
		}
		cout<<p<<endl;
		n--;
	}
	return 0;
}

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

int main(void){
	int num;
	std::cin >> num;

	std::string event;
	int out = 0, runner = 0, point = 0;
	for(int i = 0; i < num; ++i){
		while(out < 3){
			std:: cin >> event;

			if(event == "OUT"){
				++out;		
			}else if(event == "HIT"){
				if(runner == 3){
					++point;
				}else{
					++runner;
				}
			}else if(event == "HOMERUN"){
				point += ++runner;
				runner = 0;
			}
		}
		std::cout << point << std::endl;
		out = 0, runner = 0, point = 0;
	}
	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;
                runner.set(0);
                if (runner[3] == 1) {
                    ++score;
                }
            } else if ("HOMERUN" == event) {
                score += runner.count() - runner[3] + 1;
                runner.reset();
            } else if ("OUT" == event) {
                ++out;
            }
        } while(out != 3);

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

    return 0;
}