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++: #include<cstdio>
#include<cmath>
#include<algorithm>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<cstdlib>
#include<iomanip>
#include<queue>


using namespace std;

void Solution()
{
    int n;
    
    
    
    cin >> n;
    
    while(n--)
    {
        
        string str;
        
        int point = 0;
        
        int out = 0;
        
        int base[3] = {0, 0, 0};
        
        while(cin>>str)
        {
            
            if(str == "HIT")
            {
                if(base[2] == 1)
                {
                    ++point;
                    
                    base[2] = 0;
                }
                
                if(base[1] == 1)
                {
                    base[2] = 1;
                    base[1] = 0;
                }
                
                if(base[0] == 1)
                {
                    base[1] = 1;
                    base[0] = 0;
                }
                
                base[0] = 1; //point
            }
            else if(str == "HOMERUN")
            {
                for(int i=0; i < 3; ++i)
                {
                    point += base[i];
                }
                
                point++;
                
                base[0] = 0;
                base[1] = 0;
                base[2] = 0;
            }
            else
            {
                ++out;
                
                if(out >= 3)
                {
                    cout<<point<<endl;
                    
                    point = 0;
                    out = 0;
                    
                    base[0] = 0;
                    base[1] = 0;
                    base[2] = 0;
                    
                    continue;
                }
            }
        }
    }
    
}

int main()
{
    Solution();
    return 0;
}

C++: #include <iostream>
#include <string>
using namespace std;
int main(){
    int inning;
    cin >> inning;
    for(int i=0;i<inning;i++){
        int point,runner,out;
        point=runner=out=0;
        while(out!=3){
            char c[8];
            cin >> c;
            if(c[0]=='O')
                out+=1;
            if(c[0]=='H' && c[1]=='I'){
                if(runner==3)
                    point+=1;
                else
                    runner+=1;
            }
            if(c[0]=='H' && c[1]=='O'){
                point +=runner+1;
                runner =0;
            }
        }
        cout << point << endl;
    }
}

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

int main(){
	string t1("HIT"), t2("OUT"), t3("HOMERUN");
	int n;
	cin >> n;
	string s;
	for(int i = 0; i < n; i++){
		int out = 0;
		int count = 0;
		int point = 0;
		while(out != 3){
			cin >> s;
			if(s == t2){
				out++;
			}else if(s == t3){
				point += count + 1;
				count = 0;
			}else if(s == t1){
				if(count == 3) point++;
				else count++;
			}
		}
		cout << point << endl;
	}
	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 <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cstring>
#include <sstream>
#include <vector>
#include <string>
#include <iomanip>
#include <bitset>
using namespace std;
#define INF	100000000
#define MOD 1000000007
#define pb push_back
#define mp make_pair
#define fi first
#define sec second
#define lb lower_bound
#define ub upper_bound
#define SS stringstream
#define rep(i,n) for(int i = 0; i < n; i++)
#define sz(x) ((int)(x).size())
#define SORT(x) sort((x).begin(), (x).end())
#define RSORT(x) sort((x).begin(), (x).end(), greater<int>() )
#define clr(a,b) memset((a),(b),sizeof(a))
typedef long long int ll;
typedef pair<int, int> P;
typedef vector<int> Vi;
typedef vector<ll> Vll;
typedef vector<P> Vp;
typedef priority_queue<P, vector<P>, greater<P> > PQ;

int n;
int out = 0,point = 0;
bool base[3];
string str;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin >> n;
	while(true){
		cin >> str;
		if(str[0] == 'O'){
			out++;
			if(out%3 == 0){
				cout << point << endl;
				point = 0;
				rep(i,3) base[i] = 0;
			}
			if(out == n*3) break;
		} else if(str[1] == 'O'){
			point++;
			rep(i,3) if(base[i]) point++;
			rep(i,3) base[i] = 0;
		} else{
			if(base[2]) point++;
			if(base[1]) base[2] = 1;
			if(base[0]) base[1] = 1;
			base[0] = 1;
		}
	}
}

C++: #include <bits/stdc++.h>
using namespace std ;

#define pb(n) push_back(n)
#define fi first
#define se second
#define X real()
#define Y imag()
#define all(r) (r).begin(),(r).end()
#define gsort(st,en) sort((st),(en),greater<int>())
#define vmax(ary) *max_element(all(ary))
#define vmin(ary) *min_element(all(ary))
#define debug(x) cout<<#x<<": "<<x<<endl
#define fcout(n) cout<<fixed<<setprecision((n))
#define scout(n) cout<<setw(n)
#define vary(type,name,size,init) vector< type> name(size,init)

#define rep(i,n) for(int i = 0; i < (int)(n);++i)
#define REP(i,a,b) for(int i = (a);i < (int)(b);++i)
#define repi(it,array) for(auto it = array.begin(),end = array.end(); it != end;++it)
#define repa(n,array) for(auto &n :(array))

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using dict = map<string,int>;
using comd = complex<double>;
using pii = pair<int,int> ;

constexpr int imax = ((1<<30)-1)*2+1 ;
constexpr int inf = 100000000;
constexpr double PI = acos(-1.0) ;
double eps = 1e-10 ;
const int dy[] = {-1,0,1,0};
const int dx[] = {0,-1,0,1};

inline bool value(int x,int y,int w,int h){
  return (x >= 0 && x < w && y >= 0 && y < h);
}

double CalcDist(comd p1, comd p2){
  return sqrt(pow(p1.X - p2.X,2.0) + pow(p1.Y -p2.Y,2.0));
}

template <typename T>
void out(deque < T > d)
{
  for(size_t i = 0; i < d.size(); i++)
  {
    debug(d[i]);
  }
}

template<typename T>
T ston(string& str, T n){
  istringstream sin(str) ;
  T num ;
  sin >> num ;
  return num ;
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int score=0;
  string s;
  int n,out=0,runner = 0;
  cin >> n;
  rep(i,n){
    out = runner = 0,score=0;
    while(1){
      cin >> s;
      if(s == "HIT"){
        if(runner & 4){
          score++;
        }
        runner = runner<<1;
        runner &= 7;
        runner |= 1;
      }
      else if(s == "OUT"){
        ++out;
      }
      else{
        if((runner & 7) == 7){
          score += 4;
          runner = 0;
        }
        else if((runner & 7) == 3){
          score += 3;
          runner = 0;
        }
        else if((runner & 7) == 1){
          score += 2;
          runner = 0;
        }
        else{
          score++;
        }
      }
//       cout << runner << " "<< score << " " << out << endl;
      if(out == 3) break;
    }
    cout << score<<endl;
  }
  return 0;
}