Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
import sys
import re


file = open(sys.argv[1], "r")

for line in file:
    ab = map((lambda x: int(x)), re.split(" +", line))
    answer = reduce((lambda x, y: x + y), ab, 0)
    digits = len(str(answer))
    print digits

Fixed submission:
#
# AIZU ONLINE JUDGE: Digit Number
# cf. http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0002&lang=jp
#


import sys
import re


#file = open(sys.argv[1], "r")

for line in sys.stdin:
    ab = map(int, re.split(" +", line))
    answer = reduce((lambda x, y: x + y), ab, 0)
    digits = len(str(answer))
    print digits

Buggy python submission (verdict: Runtime Error):
#
# AIZU ONLINE JUDGE: Digit Number
# cf. http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0002&lang=jp
#


import sys
import re


file = open(sys.argv[1], "r")

for line in file:
    ab = map((lambda x: int(x)), re.split(" +", line))
    answer = reduce((lambda x, y: x + y), ab, 0)
    digits = len(str(answer))
    print digits

file.close()

Fixed submission:
#
# AIZU ONLINE JUDGE: Digit Number
# cf. http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0002&lang=jp
#


import sys
import re


#file = open(sys.argv[1], "r")

for line in sys.stdin:
    ab = map(int, re.split(" +", line))
    answer = reduce((lambda x, y: x + y), ab, 0)
    digits = len(str(answer))
    print digits

Buggy python submission (verdict: Runtime Error):
#
# AIZU ONLINE JUDGE: Digit Number
# cf. http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0002&lang=jp
#


import sys
import re


#file = open(sys.argv[1], "r")

for line in sys.stdin:
    ab = map((int, re.split(" +", line))
    answer = reduce((lambda x, y: x + y), ab, 0)
    digits = len(str(answer))
    print digits

Fixed submission:
#
# AIZU ONLINE JUDGE: Digit Number
# cf. http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0002&lang=jp
#


import sys
import re


#file = open(sys.argv[1], "r")

for line in sys.stdin:
    ab = map(int, re.split(" +", line))
    answer = reduce((lambda x, y: x + y), ab, 0)
    digits = len(str(answer))
    print digits
Buggy python submission (verdict: Time Limit Exceeded):
import sys


def prime_list(n):
    limit = int(n ** 0.5) + 1
    lis = range(1, n + 1, 2)
    lis[0] = 2
    while True:
        if len(lis) == 0:
            break
        p = lis.pop(0)
        yield p
        if p <= limit:
            lis = [x for x in lis if x % p != 0]


def primes_number(n):
    primes = []
    for p in prime_list(n):
       primes.append(p)
    return len(primes)


#input_file = open(sys.argv[1], "r")

#for line in input_file:
for line in sys.stdin:
    n = int(line)
    print primes_number(n)

Fixed submission:

import sys


def prime_list(n):
    limit = int(n ** 0.5) + 1
    lis = range(1, n + 1, 2)
    lis[0] = 2
    while True:
        if len(lis) == 0:
            break
        p = lis.pop(0)
        yield p
        if p <= limit:
            lis = [x for x in lis if x % p != 0]


def primes_number(n):
    primes = []
    for p in prime_list(n):
       primes.append(p)
    return primes


ns = map(int, sys.stdin.readlines())
max_n = max(ns)

primes = primes_number(max_n)


for n in ns:
    p = len(filter(lambda x: x <= n, primes))
    print p

Buggy python submission (verdict: Time Limit Exceeded):
import sys


def prime_list(n):
    limit = int(n ** 0.5) + 1
    lis = range(1, n + 1, 2)
    lis[0] = 2
    while True:
        if len(lis) == 0:
            break
        p = lis.pop(0)
        yield p
        if p <= limit:
            lis = [x for x in lis if x % p != 0]


def primes_number(n):
    primes = []
    for p in prime_list(n):
       primes.append(p)
    return len(primes)


#input_file = open(sys.argv[1], "r")

#for line in input_file:
for line in sys.stdin:
    n = int(line)
    print primes_number(n)

Fixed submission:

import sys


def prime_list(n):
    limit = int(n ** 0.5) + 1
    lis = range(1, n + 1, 2)
    lis[0] = 2
    while True:
        if len(lis) == 0:
            break
        p = lis.pop(0)
        yield p
        if p <= limit:
            lis = [x for x in lis if x % p != 0]


def primes_number(n):
    primes = []
    for p in prime_list(n):
       primes.append(p)
    return primes


ns = map(int, sys.stdin.readlines())
max_n = max(ns)

primes = primes_number(max_n)


for n in ns:
    p = len(filter(lambda x: x <= n, primes))
    print p
Buggy python submission (verdict: Runtime Error):

import sys
import math


class Circle:
    def __init__(self, x, y, r):
        self.x = x
        self.y = y
        self.r = r

    def distance(self, other):
        dx = self.x - other.x
        dy = self.y - other.y
        return math.sqrt(dx ** 2 + dy ** 2)

    def intersection(self, other):
        d = self.distance(other)
        if self.r > d + other.r:
            return 2
        elif other.r > d + self.r:
            return -2
        elif d =< self.r + other.r:
            return 1
        else:
            return 0


#input_file = open(sys.argv[1], "r")

sys.stdin.readline()

for line in sys.stdin:
    (xa, ya, ra, xb, yb, rb) = tuple(map(float, line.split(' ')))
    ca = Circle(xa, ya, ra)
    cb = Circle(xb, yb, rb)
    print ca.intersection(cb)

Fixed submission:

import sys
import math


class Circle:
    def __init__(self, x, y, r):
        self.x = x
        self.y = y
        self.r = r

    def distance(self, other):
        dx = self.x - other.x
        dy = self.y - other.y
        return math.sqrt(dx ** 2 + dy ** 2)

    def intersection(self, other):
        d = self.distance(other)
        if self.r > d + other.r:
            return 2
        elif other.r > d + self.r:
            return -2
        elif d <= self.r + other.r:
            return 1
        else:
            return 0


#input_file = open(sys.argv[1], "r")

sys.stdin.readline()

for line in sys.stdin:
    (xa, ya, ra, xb, yb, rb) = tuple(map(float, line.split(' ')))
    ca = Circle(xa, ya, ra)
    cb = Circle(xb, yb, rb)
    print ca.intersection(cb)
Buggy python submission (verdict: Runtime Error):

import sys


def fill_balls(a):
    b = [0]
    c = [0]
    for ball in a:
        if b[-1] == 0:
            b.append(ball)
        elif b[-1] < ball and c[-1] < ball:
            if b[-1] < c[-1]:
                c.append(ball)
            else:
                b.append(ball)
        elif b[-1] < ball:
            b.append(ball)
        elif c[-1] < ball:
            c.append(ball)
        else:
            return 'NO'
    return 'YES'


sys.stdin.readline()

for line in sys.stdin:
    a = map(int, line.split(' '))
    print fill_balls(a)

Fixed submission:

import sys


def fill_balls(a):
    b = [0]
    c = [0]
    for ball in a:
        if b[-1] == 0:
            b.append(ball)
        elif b[-1] < ball and c[-1] < ball:
            if b[-1] < c[-1]:
                c.append(ball)
            else:
                b.append(ball)
        elif b[-1] < ball:
            b.append(ball)
        elif c[-1] < ball:
            c.append(ball)
        else:
            return 'NO'
    return 'YES'



for i in range(input()):
    a = map(int, raw_input().split(' '))
    print fill_balls(a)
Buggy python submission (verdict: Runtime Error):
from math import pi
n = int(raw_input())
print "{0:.6f} {1:.6f}".format(n**2*pi, 2*n*pi)

Fixed submission:
from math import pi
n = float(raw_input())
print "{0:.6f} {1:.6f}".format(n**2*pi, 2*n*pi)
Buggy python submission (verdict: Runtime Error):
print " ".join(sorted(map(int, raw_input().split()), reverse=True)) 

Fixed submission:
print " ".join([str(x) for x in sorted(map(int, raw_input().split()))])
Buggy python submission (verdict: Runtime Error):
print "\n".join["Hello World" for x in xrange(1000)]

Fixed submission:
print ("Hello World\n"*1000)[:-1]
Buggy python submission (verdict: Runtime Error):
while(True):
    n = map(int, raw_input().split())
    if n[0] == -1 and n[1] == -1 and n[-2] == -1:
        break
    if n[0] == -1 or n[1] == -1:
        print "F"
    elif n[0]+n[1] >= 80:
        print "A"
    elif n[0]+n[1] >= 65:
        print "B"
    elif n[0]+n[1] >= 50:
        print "C"
    elif n[0]+n[1] >= 30:
        if n[2] >= 50:
            print "C"
        else:
            print "D"
    else:
        print "F"
GINOPC-003M-no-MacB

Fixed submission:
while(True):
    n = map(int, raw_input().split())
    if n[0] == -1 and n[1] == -1 and n[-2] == -1:
        break
    if n[0] == -1 or n[1] == -1:
        print "F"
    elif n[0]+n[1] >= 80:
        print "A"
    elif n[0]+n[1] >= 65:
        print "B"
    elif n[0]+n[1] >= 50:
        print "C"
    elif n[0]+n[1] >= 30:
        if n[2] >= 50:
            print "C"
        else:
            print "D"
    else:
        print "F"
Buggy python submission (verdict: Runtime Error):
from math import sqrt
n = map(int, raw_input().split())
print "{0:.8f}".format(sqrt((n[0]-n[2])**2+(n[1]+n[3])**2))

Fixed submission:
from math import sqrt
n = map(float, raw_input().split())
print "{0:.8f}".format(sqrt((n[0]-n[2])**2+(n[1]-n[3])**2))
Buggy python submission (verdict: Runtime Error):
# -*- utf-8 -*-

while True:
    i = map(int, raw_input().split())
    if i == None:
        break
    a = i[0]
    b = i[1]
    
    s = a + b
    
    ans = 0
    
    while s >= 1:
        s /= 10
        ans += 1
    
    print ans

Fixed submission:
# -*- utf-8 -*-

while True:
    try:
        inp = raw_input()
        i = map(int, inp.split())
        a = i[0]
        b = i[1]
    
        s = a + b
    except:
        break
    
    ans = 0
    
    while s >= 1:
        s /= 10
        ans += 1
    
    print ans

Buggy python submission (verdict: Runtime Error):
# -*- utf-8 -*-

while True:
    inp = raw_input()
    if inp == None:
        break
    i = map(int, inp.split())
    a = i[0]
    b = i[1]
    
    s = a + b
    
    ans = 0
    
    while s >= 1:
        s /= 10
        ans += 1
    
    print an

Fixed submission:
# -*- utf-8 -*-

while True:
    try:
        inp = raw_input()
        i = map(int, inp.split())
        a = i[0]
        b = i[1]
    
        s = a + b
    except:
        break
    
    ans = 0
    
    while s >= 1:
        s /= 10
        ans += 1
    
    print ans

Buggy python submission (verdict: Runtime Error):
# -*- utf-8 -*-

while True:
    inp = raw_input()
    if inp == None:
        break
    i = map(int, inp.split())
    a = i[0]
    b = i[1]
    
    s = a + b
    
    ans = 0
    
    while s >= 1:
        s /= 10
        ans += 1
    
    print ans

Fixed submission:
# -*- utf-8 -*-

while True:
    try:
        inp = raw_input()
        i = map(int, inp.split())
        a = i[0]
        b = i[1]
    
        s = a + b
    except:
        break
    
    ans = 0
    
    while s >= 1:
        s /= 10
        ans += 1
    
    print ans

Buggy python submission (verdict: Runtime Error):
# -*- utf-8 -*-

while True:
    inp = raw_input()
    if inp == "":
        break
    i = map(int, inp.split())
    a = i[0]
    b = i[1]
    
    s = a + b
    
    ans = 0
    
    while s >= 1:
        s /= 10
        ans += 1
    
    print ans

Fixed submission:
# -*- utf-8 -*-

while True:
    try:
        inp = raw_input()
        i = map(int, inp.split())
        a = i[0]
        b = i[1]
    
        s = a + b
    except:
        break
    
    ans = 0
    
    while s >= 1:
        s /= 10
        ans += 1
    
    print ans

Buggy python submission (verdict: Runtime Error):
# -*- utf-8 -*-

while True:
    inp = raw_input()
    if inp == "":
        break
    i = map(int, inp.split())
    a = i[0]
    b = i[1]
    
    s = a + b
    
    ans = 0
    
    while s >= 1:
        s /= 10
        ans += 1
    
    print ans

Fixed submission:
# -*- utf-8 -*-

while True:
    try:
        inp = raw_input()
        i = map(int, inp.split())
        a = i[0]
        b = i[1]
    
        s = a + b
    except:
        break
    
    ans = 0
    
    while s >= 1:
        s /= 10
        ans += 1
    
    print ans
Buggy python submission (verdict: Runtime Error):
line = input()
reversed(line)
print line

Fixed submission:
line = raw_input().strip()
print reduce(lambda a, b: a + b, reversed(line))
Buggy python submission (verdict: Runtime Error):
def foo(n):
    ret = ""
    n = str(n)
    cnt = 1
    for i in range(1, len(n)):
        if n[i - 1] == n[i]:
            cnt += 1
            continue
        else:
            ret += str(cnt) + n[i - 1]
            cnt = 1

    ret += str(cnt) + n[-1]

    return long(ret)


while 1:
    n = input()
    if n == 0:
        break
    m = input()
    for i in range(n):
        m = foo(m)
    print m

Fixed submission:
def foo(n):
    ret = ""
    cnt = 1
    for i in range(1, len(n)):
        if n[i - 1] == n[i]:
            cnt += 1
            continue
        else:
            ret += str(cnt) + n[i - 1]
            cnt = 1

    ret += str(cnt) + n[-1]

    return ret


while 1:
    n = input()
    if n == 0:
        break
    m = raw_input().strip()
    for i in range(n):
        m = foo(m)
    print m
Buggy python submission (verdict: Runtime Error):
import sys
import math
for line in sys.stdin:
        a =map(int,raw_input().split())
        b = a[0] + a[1]
        print int(math.log10(b)+1)

Fixed submission:
import math
while True:
        try:
                a =map(int,raw_input().split())
                b = a[0] + a[1]
                print len(str(a[0]+a[1]))
        except EOFError:
                break

Buggy python submission (verdict: Runtime Error):
import sys
import math
for a in sys.stdin:
        a =map(int,raw_input().split())
        b = a[0] + a[1]
        print int(math.log10(b)+1)

Fixed submission:
import math
while True:
        try:
                a =map(int,raw_input().split())
                b = a[0] + a[1]
                print len(str(a[0]+a[1]))
        except EOFError:
                break

Buggy python submission (verdict: Runtime Error):
import sys
import math
while True:
        a =map(int,raw_input().split())
        b = a[0] + a[1]
        print int(math.log10(b)+1)

Fixed submission:
import math
while True:
        try:
                a =map(int,raw_input().split())
                b = a[0] + a[1]
                print len(str(a[0]+a[1]))
        except EOFError:
                break
Buggy python submission (verdict: Runtime Error):
import pi
a = float(raw_input())
print"%.6f %.6f" %(pi*a**2,2*pi*a)

Fixed submission:
import math
a = float(raw_input())
print"%.6f %.6f" %(math.pi*a**2,2*math.pi*a)
Buggy python submission (verdict: Runtime Error):
a =map(int,raw_input().split())
if a[0]>a[1]:
        print "a>b"
elif a[0]<a[1]:
        print "a<b"
else:
        print "a==b"
~                       

Fixed submission:
a =map(int,raw_input().split())
if a[0]>a[1]:
        print "a > b"
elif a[0]<a[1]:
        print "a < b"
else:
        print "a == b"

Buggy python submission (verdict: Runtime Error):
a =map(int,raw_input().split())
if a[0]>a[1]:
        print "a > b"
elif a[0]<a[1]:
        print "a < b"
else:
        print "a == b"
~                       

Fixed submission:
a =map(int,raw_input().split())
if a[0]>a[1]:
        print "a > b"
elif a[0]<a[1]:
        print "a < b"
else:
        print "a == b"
Buggy python submission (verdict: Time Limit Exceeded):
# Prime Number

import sys


def count_prime_numer(n):
	if n <= 1:
		return 0
	elif n == 2:
		return 1
	else:
		count = 1
		for prime in xrange(3, n + 1, 2):
			for i in xrange(3, prime - 1):
				if prime % i == 0:
					break
			else:
				count += 1
		return count

datas = []

for line in sys.stdin:
	datas.append(int(line))

for data in datas:
	print count_prime_numer(data)

Fixed submission:
# Prime Number

import sys


MAX_NUM = 1000000
ROOT_MAX_NUM = 1000

primes = [1] * MAX_NUM

primes[0] = primes[1] = 0

for i in xrange(2, ROOT_MAX_NUM):
	if not primes[i]:
		continue
	for j in xrange(i+i, MAX_NUM, i):
		primes[j] = 0

datas = []

for line in sys.stdin:
	datas.append(int(line))

for data in datas:
	count = 0
	for i in xrange(data+1):
		if primes[i]:
			count += 1
	print count

Buggy python submission (verdict: Time Limit Exceeded):
# Prime Number

import sys
import math


primes = [2]

for prime in xrange(3, 1000000, 2):
	for i in xrange(3, int(math.sqrt(prime)) + 1):
		if prime % i == 0:
			break
	else:
		primes.append(prime)

datas = []

for line in sys.stdin:
	datas.append(int(line))

for data in datas:
	count = 0
	for prime in primes:
		if prime <= data:
			count += 1
		else:
			break
	print count

Fixed submission:
# Prime Number

import sys


MAX_NUM = 1000000
ROOT_MAX_NUM = 1000

primes = [1] * MAX_NUM

primes[0] = primes[1] = 0

for i in xrange(2, ROOT_MAX_NUM):
	if not primes[i]:
		continue
	for j in xrange(i+i, MAX_NUM, i):
		primes[j] = 0

datas = []

for line in sys.stdin:
	datas.append(int(line))

for data in datas:
	count = 0
	for i in xrange(data+1):
		if primes[i]:
			count += 1
	print count

Buggy python submission (verdict: Time Limit Exceeded):
# Prime Number

import sys


count = 0
primes = [2, 3]

for n in xrange(5, 1000001, 2):
	isprime = True
	for i in xrange(1, len(primes)):
		count += 1
		if primes[i] * primes[i] > n:
			break
		count += 1
		if n % primes[i] == 0:
			isprime = False
			break
	if isprime:
		primes.append(n)

datas = []

for line in sys.stdin:
	datas.append(int(line))

for data in datas:
	count = 0
	for prime in primes:
		if prime <= data:
			count += 1
		else:
			break
	print count

Fixed submission:
# Prime Number

import sys


MAX_NUM = 1000000
ROOT_MAX_NUM = 1000

primes = [1] * MAX_NUM

primes[0] = primes[1] = 0

for i in xrange(2, ROOT_MAX_NUM):
	if not primes[i]:
		continue
	for j in xrange(i+i, MAX_NUM, i):
		primes[j] = 0

datas = []

for line in sys.stdin:
	datas.append(int(line))

for data in datas:
	count = 0
	for i in xrange(data+1):
		if primes[i]:
			count += 1
	print count
Buggy python submission (verdict: Runtime Error):
import sys
heights = []
for line in sys.stdin:
    heights.append(int(line.rstrip('\n')))
for height in heights.sort()[:3]:
    print height

Fixed submission:
import sys
heights = []
for line in sys.stdin:
    heights.append(int(line.rstrip('\n')))
for height in sorted(heights, reverse=True)[:3]:
    print height
Buggy python submission (verdict: Runtime Error):
import sys

for lineCnt, line in enumerate(sys.stdin):
    if lineCount == 0: continue
    a, b, c = map(int, line.rstrip('\n').split(' '))
    if a+b>c and b+c>a and c+a>b:
        print 'YES'
    else:
        print 'NO'

Fixed submission:
import sys

for lineCount, line in enumerate(sys.stdin):
    if lineCount == 0:
        continue
    a, b, c = sorted(map(int, line.split(' ')))
    if a**2 + b**2 == c**2:
        print 'YES'
    else:
        print 'NO'

Buggy python submission (verdict: Runtime Error):
import sys

for lineCount, line in enumerate(sys.stdin):
    if lineCount == 0:
        continue
    a, b, c = sorted(map(int, line.split(' ')))
    if a**2 + b**2 = c**2:
        print 'YES'
    else:
        print 'NO'

Fixed submission:
import sys

for lineCount, line in enumerate(sys.stdin):
    if lineCount == 0:
        continue
    a, b, c = sorted(map(int, line.split(' ')))
    if a**2 + b**2 == c**2:
        print 'YES'
    else:
        print 'NO'
Buggy python submission (verdict: Runtime Error):
import sys

for line in sys.stdin:
    a, b = sorted(map(int, line.split(' ')))
    gcd = 1
    div = 2
    while a >= div:
        amod, bmod = a % div, b % div
        if amod == 0 and bmod == 0;
            gcd *= div
            a, b = a/div, b/div
            continue
        else:
            div += 2
    lcm = gcd * a * b
    print gcd, lcm

Fixed submission:
import sys

for line in sys.stdin:
    a, b = sorted(map(int, line.split(' ')))
    gcd = 1
    d = 2
    while a >= d:
        amod, bmod = a % d, b % d
        if amod == 0 and bmod == 0:
            gcd *= d
            a, b = a/d, b/d
            d = 2
            continue
        else:
            d += 1
    lcm = gcd * a * b
    print gcd, lcm

Buggy python submission (verdict: Runtime Error):
import sys

for line in sys.stdin:
    a, b = sorted(map(int, line.split(' ')))
    gcd = 1
    div = 2
    while a >= div:
        amod, bmod = a % div, b % div
        if amod == 0 and bmod == 0;
            gcd *= div
            a, b = a/div, b/div
            div = 2
            continue
        else:
            div += 1
    lcm = gcd * a * b
    print gcd, lcm

Fixed submission:
import sys

for line in sys.stdin:
    a, b = sorted(map(int, line.split(' ')))
    gcd = 1
    d = 2
    while a >= d:
        amod, bmod = a % d, b % d
        if amod == 0 and bmod == 0:
            gcd *= d
            a, b = a/d, b/d
            d = 2
            continue
        else:
            d += 1
    lcm = gcd * a * b
    print gcd, lcm

Buggy python submission (verdict: Runtime Error):
import sys

for line in sys.stdin:
    a, b = sorted(map(int, line.split(' ')))
    gcd = 1
    d = 2
    while a >= d:
        amod, bmod = a % d, b % d
        if amod == 0 and bmod == 0;
            gcd *= d
            a, b = a/d, b/d
            d = 2
            continue
        else:
            d += 1
    lcm = gcd * a * b
    print gcd, lcm

Fixed submission:
import sys

for line in sys.stdin:
    a, b = sorted(map(int, line.split(' ')))
    gcd = 1
    d = 2
    while a >= d:
        amod, bmod = a % d, b % d
        if amod == 0 and bmod == 0:
            gcd *= d
            a, b = a/d, b/d
            d = 2
            continue
        else:
            d += 1
    lcm = gcd * a * b
    print gcd, lcm
Buggy python submission (verdict: Runtime Error):
import sys

for line in sys.stdin:
    print sorted(line, reversed=True)

Fixed submission:
import sys

for line in sys.stdin:
    l = [ c for c in line.rstrip('\n') ]
    l.reverse()
    print ''.join(l)

Buggy python submission (verdict: Runtime Error):
import sys

for line in sys.stdin:
    l = line.rstrip('\n').split('')
    l.reverse()
    print ''.join(l)

Fixed submission:
import sys

for line in sys.stdin:
    l = [ c for c in line.rstrip('\n') ]
    l.reverse()
    print ''.join(l)
Buggy python submission (verdict: Runtime Error):
import sys

for line in sys.stdin:
    result =, 0
    d = int(line)
    x = d
    while x < 600:
        result += x**2 * d
    print result

Fixed submission:
import sys

for line in sys.stdin:
    result = 0
    d = int(line)
    x = d
    while x < 600:
        result += x**2 * d
        x += d
    print result

Buggy python submission (verdict: Time Limit Exceeded):
import sys

for line in sys.stdin:
    result = 0
    d = int(line)
    x = d
    while x < 600:
        result += x**2 * d
    print result

Fixed submission:
import sys

for line in sys.stdin:
    result = 0
    d = int(line)
    x = d
    while x < 600:
        result += x**2 * d
        x += d
    print result
Buggy python submission (verdict: Runtime Error):
n=int(raw_input())
game=0
while game<n:
    run=0
    score=0
    out=0
    while out<3:
        ev=raw_input()
        if ev=='OUT':
            out=out+1
        elif ev=='HIT':
            run=run+1
            if run>3:
                run=3
                score=score+1
        else:
            score=score+run+1
            run=0
    print score
    game=game+1
    

Fixed submission:
n=int(raw_input())
game=0
while game<n:
    run=0
    score=0
    out=0
    while out<3:
        ev=raw_input()
        if ev=='OUT':
            out=out+1
        elif ev=='HIT':
            run=run+1
            if run>3:
                run=3
                score=score+1
        else:
            score=score+run+1
            run=0
    print score
    game=game+1