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)
	}
}

Python: a = int(input().rstrip())
b = 0
while a > b:
	c = 0
	runner = 0
	point = 0
	while c < 3:
		x = input().rstrip()
		if x == HIT:
			if runner == 3:
				point += 1
			else:
				runner += 1
		elif x == HOMERUN:
			point = point + runner + 1
			runner = 0
		else:
			c += 1
	print(point)

Python: n = int(input())
for i in range(n):
	o_count = 0
	h_count = 0
	score = 0
	while True:
		site = input()
		if site == 'OUT':
			o_count += 1
			if o_count == 3:
				print(score)
				break
		elif site == 'HIT':
			if h_count == 3:
				score += 1
			else:
				h_count += 1
		else:
			score += h_count+1
			h_count = 0

Python: N = int(input())
for i in range(N):
    out = 0
    hit = 0
    point = 0
    
    while out < 3 :
         a = input()
         if a == "HIT":
              if hit < 3:
                   hit = hit + 1
              else:
                  point = point + 1
         elif a == "HOMERUN":
            point += hit + 1
            hit = 0
         elif a == "OUT":
            out += 1
    print(point)

Python: for i in range(int(input())):
    f, s, t, count, point = 0, 0, 0, 0, 0
    while count != 3:
        data = input()
        if data == 'HIT':
            if t == 1:
                point += 1
                t = 0
            if s == 1:
                t = 1
                s = 0
            if f == 1:
                s = 1
            f = 1
        elif data == 'OUT':
            count += 1
        elif data == 'HO' \
                   '' :
            point += f + s + t + 1
            f, s, t = 0, 0, 0
    print(point)

Python: #演習１－１４
sys_a = [0]*2 #aの攻撃システム[ランナー,アウト]　
sys_b = [0]*2 #bの攻撃システム[ランナー,アウト]
score_a = 0 #socre of a
score_b = 0 #score of b
outs = 0 #total number of outs (1 ining = 6 outs)
inings = int(input()) #number of inings

while outs <= 3*inings:
    
    if outs == 3*inings: #outsが3回×イニング数　個たまったらおわり
        break
          
    else:
        action = input()
        if action == "OUT":
            if sys_a[-1] != 2:
                sys_a[-1] = sys_a[-1]+1
                outs = outs + 1
            else :
                print(score_a)
                score_a = 0
                sys_a = [0] * 2
                outs = outs +1
                
        elif action == "HOMERUN":
            score_a += sys_a[0] +1
            sys_a[0] = 0
        else :
            if sys_a[0] == 3:
                score_a = score_a+1
                sys_a[0] = 3
            else:
                sys_a[0] = sys_a[0]+ 1

Python: n = int(input())

for i in range(n):
    b = [False,False,False]
    o = 0
    p = 0
    while o < 3:
        e = input()
        if e == "HIT":
            if b[2]:
                p += 1
            b[1], b[2] = b[0], b[1]
            b[0] = True
        elif e == "HOMERUN":
            p += b.count(True) + 1
            b = [False,False,False]
        else:
            o += 1
    print(p)

Python: for i in range(int(input())):
    p1 = p2 = p3 = out = cnt = 0
    while True:
        s = input()
        if s =="HIT":
            if p3 > 0:
                cnt += 1
            p3, p2, p1 = p2, p1, 1
        elif s == "HOMERUN":
            cnt += p1 + p2 + p3 +1
            p1 = p2 = p3 = 0
        else:
            out += 1
            if out == 3:
                break
    print(cnt)

Python: n = int(input())
for i in range(n):
  l = [1,0,0,0]
  c = 0
  o_c = 0
  while True:
    s = input()
    if s == 'HIT':
      if l[3] == 1:
        c += 1
      for i in range(4):
        if i == 3:
          l[3-i] == 1
        else:
          l[3-i] = l[2-i]
    elif s == 'HOMERUN':
      c += sum(l)
      l = [1,0,0,0]
    else:
      o_c += 1
      if o_c == 3:
        print(c)
        break

Python: n = int(input())
inning = 0

while inning != n:
    score = 0
    info = [0, 0, 0]
    out_count = 0
    while True:
        event = input()
        if event == "OUT":
            out_count += 1
        if out_count == 3:
            inning += 1
            print(score)
            break

        if event == "HIT":
            score += info[-1]
            info = [1] + info[:2]
        elif event == "HOMERUN":
            score += sum(info) + 1
            info = [0, 0, 0]

Python: n = int(input())
for i in range(n):
    out_count = 0
    score = 0
    runner = []
    while True:
        if out_count == 3:
            print(score)
            break
            
        events = input()
        if events == "HIT":
            if len(runner) == 3:
                score += 1
            else:
                runner.append(1)

        elif events == "HOMERUN":
            score += len(runner) + 1
            runner = []

        elif events == "OUT":
            out_count += 1

Python: n = int(input())
for i in range(n):
    no = 0
    np = 0
    tm = 0
    while(True):
        s = input()
        if s == "HIT":
            tm += 1
            if tm >= 4:
                np += 1
                tm = 3
        if s == "HOMERUN":
            np += tm +1
            tm = 0
        if s == "OUT":
            no += 1
        if no >= 3:
            print(np)
            break

Python: # Aizu Problem 0103: Baseball Simulation
#
import sys, math, os

# read input:
PYDEV = os.environ.get('PYDEV')
if PYDEV=="True":
    sys.stdin = open("sample-input.txt", "rt")


N = int(input())
for n in range(N):
    bases = [0, 0, 0]
    outs = 0
    score = 0
    while outs < 3:
        event = input().strip()
        if event == "OUT":
            outs += 1
        elif event == "HOMERUN":
            score += 1 + sum(bases)
            bases = [0, 0, 0]
        elif event == "HIT":
            score += bases[2]
            bases[1:] = bases[:2]
            bases[0] = 1
    print(score)

Python: a=0
while 1:
 OUT=0
 R=0
 P=0
 SET=0
 
 if a==0:
     b=int(input())
     a+=1
 if b==0:
     break
 
 
 while OUT<=2:
    n=input()
    
    if n=='HIT':
        R+=1
        if R>3:
            P+=1
            R=3
    if n=='OUT':
        OUT+=1
    if n=='HOMERUN':
        P+=R+1
        R=0

    
        
 b-=1
 print(P)
P=0

Python: n = int(input())

for i in range(n):
    out_cnt = 0
    score = 0
    runner = [0,0,0,0]
    while True:
        event = input()
        if event=="OUT":
            out_cnt += 1
            if out_cnt == 3:
                break

        elif event=="HIT":
            if 1 in runner:
                for ind in range(len(runner)-1,-1,-1):
                    if runner[ind] == 1:
                        if ind != 3:
                            runner[ind] = 0
                            runner[ind+1] = 1
                            if not 1 in runner[:ind]:
                                break
                if runner[-1]==1:
                    runner[-1] = 0
                    score += 1    
                runner[0] = 1           
            else:
                runner[0] = 1

        elif event=="HOMERUN":
            score += sum(runner)+1
            runner = [0,0,0,0]
    print(score)