n=int(input())
jia_win=0
yi_win=0
ping=0
jiac=0
jiaj=0
jiab=0
yic=0
yib=0
yij=0
for i in range(0,n):
jia,yi=input().split()
if jia==yi:
ping+=1
if (jia=='C' and yi=='J'):
jia_win+=1
jiac+=1
if (jia=='B' and yi=='C'):
jia_win+=1
jiab+=1
if (jia=='J' and yi=='B'):
jia_win+=1
jiaj+=1
if (yi=='C' and jia=='J'):
yi_win+=1
yic+=1
if (yi=='B' and jia=='C'):
yi_win+=1
yib+=1
if (yi=='J' and jia=='B'):
yi_win+=1
yij+=1
print("%d %d %d"%(jia_win,ping,yi_win))
print("%d %d %d"%(yi_win,ping,jia_win))
if max(jiab,jiac,jiaj)==jiab and (jiac!=jiab and jiaj!=jiab):
print('B',end=' ')
elif max(jiab,jiac,jiaj)==jiac and (jiac!=jiab and jiac!=jiaj):
print('C',end=' ')
elif max(jiab,jiac,jiaj)==jiaj and (jiaj!=jiab and jiac!=jiaj):
print('J',end=' ')
if (jiac==jiab or jiaj==jiab) and max(jiab,jiac,jiaj)==jiab:
print('B',end=' ')
elif (jiac==jiaj) and max(jiab,jiac,jiaj)==jiac:
print('C',end=' ')
if max(yic,yib,yij)==yic and (yij!=yib and yic!=yij):
print('C')
elif max(yic,yib,yij)==yib and (yic!=yib and yij!=yib):
print('B')
elif max(yic,yib,yij)==yij and (yij!=yib and yic!=yij):
print('J')
if (yic==yib or yij==yib) and max(yic,yib,yij)==yib:
print('B')
elif(yic==yij) and max(yic,yib,yij)==yic:
print('C')