#include<string.h>
#include<stdio.h>
int main()
{
int t,len,count=0;
char str[101];
scanf("%d",&t);
while(t–>0)
{
scanf("%s",&str);
len=strlen(str);
for(int i=0;i<len;i++)
{
if(str[i]==‘A’ || str[i]==‘D’ || str[i]==‘O’ || str[i]==‘P’ || str[i]==‘R’)
{
count=count+1;
}
if (str[i]=='B')
{
count=count+2;
}
}
printf("%d\n",count);
count=0;
}
return 0;
}