#include “stdio.h”
#include “string.h”
int main()
{
int a,i,j;
int counter = 0;
char string [101];
scanf("%d",&a);
for(i=0;i<a;i++)
{
scanf("%s", string);
for(j = 0; j < strlen (string); j++)
{
switch (string[j]){
case 'A':
counter++;
break;
case 'D':
counter++;
break;
case 'O':
counter++;
break;
case 'P':
counter++;
break;
case 'R':
counter++;
break;
case 'B':
counter+=2;;
break;
}
}
printf("%d\n",counter);
counter = 0;
}
return 0;
}