Hide

Problem A
What's in an (Apaxian) Name?

It has been an exciting summer for the Oriental Institute researchers who specialize in the ancient Apaxian civilization, which sounds made-up but most certainly is not. While conducting a survey of the Chicago Tunnel Company’s abandoned tunnels, one of their archaelogists came upon a secret chamber containing a copy of the Codex Mendax, one of the most venerable texts in ancient Apaxian society.

The Codex Mendax has revealed that Apaxian society was divided into distinct communities, each with its own name. Not just that, the names of the Apaxians in a community would, in turn, include the name of the community itself. The location of the community’s name in a person’s name indicated their status in the community:

  • If the community name appears at the start of the person’s name, that person was a princess.

  • If the community name appears at the end of the person’s name, that person was a baron.

  • If the community name appears in the middle of the person’s name, that person was a priest.

  • If the community name does not appear anywhere in the person’s name, that person was considered a commoner in that community (although that same person could have a different status in a different community).

For example, suppose there was an Apaxian community called mentior:

  • mentioromenas was a princess.

  • summentior was a baron.

  • asmentiorones was a priest.

  • menolaxios was a commoner.

The Codex Mendax also states that a community name never appears more than once in an Apaxian name. Furthermore, no person in a community can have the exact same name as that community (so, for example, no one in the mentior community could be called mentior).

In light of this new information about Apaxian naming conventions, the Oriental Institute is drawing upon our programming prowess to analyze a batch of Apaxian names.

Input

The input starts with a line containing a community name. A community name contains only lowercase letters, no whitespace, and has a maximum length of 10 characters.

Next, the input provides a list of Apaxian names from that community. The second line of input is an integer $n$ ($1 \leqslant n \leqslant 100$) specifying the number of names. This is followed by $n$ lines, each containing a single name. Each name contains only lowercase letters, no whitespace, and has a maximum length of 50 characters.

Output

You must count the number of princesses, the number of barons, the number of priests, and the number of commoners in the list of names provided in the input. The output will be the following four lines:

p PRINCESS
h BARON
r PRIEST
c COMMONER

Where you must replace p with the number of princesses, h with the number of philosophers, etc.

Sample Input 1 Sample Output 1
mentior
4
mentioromenas
asmentiorones
summentior
menolaxios
1 PRINCESS
1 BARON
1 PRIEST
1 COMMONER
Sample Input 2 Sample Output 2
ios
3
apalaxios
menolaxios
somolaxios
0 PRINCESS
3 BARON
0 PRIEST
0 COMMONER

Please log in to submit a solution to this problem

Log in