# 次数
N = eval(input())
list1 = {'B': 0, 'C': 0, 'J': 0}
list2 = {'B': 0, 'C': 0, 'J': 0}
jia = 0
bi = 0
for i in range(N):
a, b = map(str, input().split())
if a == 'C':
if b == 'J':
jia += 1
list1['C'] += 1
elif b == 'B':
bi += 1
list2['B'] += 1
elif a == 'J':
if b == 'C':
bi += 1
list2['C'] += 1
elif b == 'B':
jia += 1
list1['J'] += 1
else:
if b == 'J':
bi += 1
list2['J'] += 1
elif b == 'C':
jia += 1
list1['B'] += 1
ping = N - jia - bi
# 排序
list1 = sorted(list1.items(), key=lambda item: item[1], reverse=True)
list2 = sorted(list2.items(), key=lambda item: item[1], reverse=True)
# 输出甲乙胜平负
print(jia, ping, bi)
print(bi, ping, jia)
print(list1[0][0], list2[0][0])