//this program is running succesfully…but the codechef admin does not accept it…why so??
#include<stdio.h>
#include<string.h>
int main()
{
char a[100];
int i,c,t;
scanf("%d",&t);
while(t!=0)
{ scanf("%s",a);
c=0;
for(i=0;i<strlen(a);i++)
{
if((a[i]=='A')|| (a[i]=='P')||(a[i]=='D')||(a[i]=='R')||(a[i]=='O')||(a[i]=='Q'))
c++;
else if(a[i]=='B')
c=c+2;
}
printf("%d",c);
t--;
}
return 0;
}