#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int,int>;
const int N = 1e6+10;
int t,n,m,k,l,r,op,x,y;
string str;
void solve(){
cin>>n;
for(int i = 1;i<=n;i++){
cin>>str;
for(char&ch:str){
if(ch=='J')t+=1;
else if(ch=='Q')t+=2;
else if(ch=='K')t+=3;
else if(ch=='A')t+=4;
// else if(isdigit(ch))t+=ch-'0';
}
}
cout<<t;
}
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
solve();
return 0;
}