//I have a code below which when I submit shows NZEC by the online judge. Can anyone please help me in finding the problem
import java.io.*;
class Holes{
public static void main(String args[]) throws Exception{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String array[] = br.readLine().split(" ");
int tc = Integer.parseInt(array[0]);
int td = Integer.parseInt(array[1]);
String str[] = new String[tc];
for(int i=0;i<tc;i++){
str[i] = br.readLine().toUpperCase();
}
for(int i=0;i<str.length;i++){
int x = count(str[i]);
System.out.println(x);
}
}
public static int count(String str){
int cnt = 0;
for(int i=0;i<str.length();i++){
if(str.charAt(i) == 'A' || str.charAt(i) == 'D' || str.charAt(i) == 'O' || str.charAt(i) == 'P' || str.charAt(i) == 'R'){
cnt++;
}
if(str.charAt(i) == 'B'){
cnt+=2;
}
}
return cnt;
}
}