#include <iostream>
#include <string>
using namespace std;
int shuchu(int a,int b,int c)
{
if(a>b&&a>c)
{
return 1;
}
else if(b>a&&b>c)
{
return 2;
}
else if(c>a&&c>b)
{
return 3;
}
else if(a==b&&b==c)
{
return 3;
}
else if(a==b)
{
return 1;
}
else if(b==c)
{
return 3;
}
else if(a==c)
{
return 3;
}
}
int main()
{
long int N;
cin>>N;
char a[100000],b[100000];
int num1C=0,num1J=0,num1B=0,num2C=0,num2B=0,num2J=0,num3=0;
int num1=0,num2=0;
for(int i=0;i<N;i++)
{
cin>>a[i]>>b[i];
}
for(int i=0;i<N;i++)
{
if(a[i]==b[i])
{
num3++;
}
else if(a[i]=='C'&&b[i]=='J')
{
num1C++;
}
else if(a[i]=='J'&&b[i]=='B')
{
num1J++;
}
else if(a[i]=='B'&&b[i]=='C')
{
num1B++;
}
else if(b[i]=='C'&&a[i]=='J')
{
num2C++;
}
else if(b[i]=='J'&&a[i]=='B')
{
num2J++;
}
else if(b[i]=='B'&&a[i]=='C')
{
num2B++;
}
}
num1=num1C+num1J+num1B;
num2=num2C+num2J+num2B;
cout<<num1<<" "<<num3<<" "<<num2<<endl;
cout<<num2<<" "<<num3<<" "<<num1<<endl;
int flag1=shuchu(num1C,num1J,num1B);
int flag2=shuchu(num2C,num2J,num2B);
if(flag1==1)
{
cout<<"C"<<" ";
}
else if(flag1==2)
{
cout<<"J"<<" ";
}
else if(flag1==3)
{
cout<<"B"<<" ";
}
if(flag2==1)
{
cout<<"C";
}
else if(flag2==2)
{
cout<<"J";
}
else if(flag2==3)
{
cout<<"B";
}
return 0;
}