Problem 1005: Fame

(ACM S.E. U.S.A. Regional 2003, problem 5)

Description

Starlet O'Hara is an up-and-coming actress. She believes it's not what you know but whom you know, and goes to numerous Hollywood parties to meet A-list people. Unfortunately, there are lots of other people at these parties and Starlet doesn't want to waste time meeting with them. Fortunately, Starlet has a friend who will get her copies of charts telling where each person will be most likely to be found at a party. She wants you to write a program to tell her how many groups of A-list people will be at each party.

The descriptions of the parties will be a rectangular grid, with a single character telling what type of person is expected to be in a place. These may be any uppercase letter. If no one is in a place, a period ('.') will be in the grid. Starlet is only interested in A-list celebrities, who are represented by the letter 'A'. To decide which party to go to, she wants to know how many four-connected groups of A's there are. A group of letters is four-connected if each cell in the group is a horizontal or vertical neighbor of another cell in the same group. Since Starlet wants to make the best use of her time, she does not want to count any group with fewer than 3 people.

Input Format

The first line of each data set is respectively the number of rows in the grid (0 <= r <= 100) and the number of columns in the grid (0 <= c <= 100). The following r lines contain c characters, either an uppercase letter or '.'. The last data set is signaled by r being 0, and should not be processed.

Output Format

Each data set should generate a line looking like .Party n has m A-list groups. where n is the current data set (starting at 1), and m is the number of 4-connected groups of A's with 3 or more members found in the current grid.

Sample Input

4 5
AAABA
A..BA
A...A
ACA.A
5 5
AA.AA
ABA.A
BAA.A
CCC.A
BAAA.
0 4

Sample Output

Party 1 has 2 A-list groups
Party 2 has 4 A-list groups

End of Problem