Holes

Count the holes in each of N lines of uppercase text, where B counts as two, A D O P Q R count as one, and the rest count as zero.

Easy2StringImplementationSimulationHash mapInterviewNo attempts yetTime limit2sMemory limit512 MB

Problem

Mike wrote some text on a piece of paper using only upper case letters and spaces, and now he wants to know how many holes the text has.

What counts as a hole here? Think of the paper as a plane and of each letter as a curve drawn on that plane. Every letter splits the plane into regions. The letters A and O split the plane into two regions, so each of them has one hole. B has two holes, and C, E, F and K have none. A space has no holes.

This problem fixes one hole count per letter. B is the only letter with two holes. The letters A, D, O, P, Q and R have one hole each. Every other upper case letter, and the space, has none.

The number of holes in a line is the sum of the holes of the letters on that line. Report that number for each line.

Input

The first line contains NN, the number of text lines that follow (0<N300 < N \le 30).

Each of the next NN lines contains text made only of upper case letters and spaces. Every such line contains at least one letter, and no line is longer than 250 characters.

Output

For each input line, print the number of holes in that line on a line of its own.