#include<bits/stdc++.h>
using namespace std;
deque<int> d[15];
char c;
int a[60],b=0;
int main(){
for(int i=1;i<=13;i++){
for(int j=1;j<=4;j++){
cin>>c;
if(c=='A') d[i].push_back(1);
else if(c=='0') d[i].push_back(10);
else if(c=='J') d[i].push_back(11);
else if(c=='Q') d[i].push_back(12);
else if(c=='K') d[i].push_back(13);
else d[i].push_back(c-'0');
}
}
while(!d[13].empty()){
int x=d[13].front();
d[x].pop_front();
while(1+1==2){
if(x==13){
break;
}
d[x].push_front(x);
a[x]++;
if(a[x]==4){
b++;
}
int y=d[x].back();
d[x].pop_back();
x=y;
}
}
cout<<b;
return 0;
}