{"raw_statement":[{"iden":"statement","content":"The organizers of the ACM Movie Night event decided to hold a voting to let members choose one of the available three movies. Each member can pick an ink-stamp of the first letter of the movie he/she wants to vote for {‘H’, ‘M’, or ‘Y’}, and use it on a big whiteboard rotated in any angle they want, but without overlapping/touching previous votes or touching the borders of the whiteboard.\n\nStamps for each movie are available in different sizes but they are all made of the same font, and all of them will leave a black mark on the whiteboard. The picture shows the used font and how the whiteboard may look at the end of the voting process (it represents an actual test case but scaled down).\n\nThe first line of input contains a single integer T (1 ≤ T ≤ 32), the number of test cases.\n\nThe first line of each test case contains two space-separated integers r and c (r, c ≤ 1000), the number of rows and columns of the image, respectively.\n\nEach of the following r lines contains c characters that are either ‘.’ (a white pixel), or ‘#’ (a black pixel).\n\nIt is guaranteed that the input is valid and matches the following constraints:\n\nThe total number of pixels in all test cases doesn't exceed 5 × 106.\n\nFor each test case, print a single line with three space-separated integers, the number of times each of ‘H’, ‘M’, and ‘Y’ appears on the whiteboard, respectively.\n\nA *connected component* is a set of black pixels such that it is possible to start at any pixel from the set and reach all other pixels by moving only to adjacent pixels. *Two pixels are adjacent if they share a corner or an edge*. A connected component is maximal if adding a new black pixel to the component will make it disconnected.\n\n"},{"iden":"input","content":"The first line of input contains a single integer T (1 ≤ T ≤ 32), the number of test cases.The first line of each test case contains two space-separated integers r and c (r, c ≤ 1000), the number of rows and columns of the image, respectively.Each of the following r lines contains c characters that are either ‘.’ (a white pixel), or ‘#’ (a black pixel).It is guaranteed that the input is valid and matches the following constraints:  All cells on the border are white.  The image contains at least one letter.  The width of any used letter before rotating it is at least 20 pixels.  Each maximal connected component of black pixels represents one of the three letters. The total number of pixels in all test cases doesn't exceed 5 × 106."},{"iden":"output","content":"For each test case, print a single line with three space-separated integers, the number of times each of ‘H’, ‘M’, and ‘Y’ appears on the whiteboard, respectively."},{"iden":"note","content":"A *connected component* is a set of black pixels such that it is possible to start at any pixel from the set and reach all other pixels by moving only to adjacent pixels. *Two pixels are adjacent if they share a corner or an edge*. A connected component is maximal if adding a new black pixel to the component will make it disconnected."}],"translated_statement":null,"sample_group":[],"show_order":[],"formal_statement":"**Definitions**  \nLet $ T \\in \\mathbb{Z} $ be the number of test cases.  \nFor each test case $ k \\in \\{1, \\dots, T\\} $:  \n- Let $ r_k, c_k \\in \\mathbb{Z} $ denote the dimensions of the grid.  \n- Let $ G_k \\in \\{ \\text{'.', '#'} \\}^{r_k \\times c_k} $ be a binary grid where `#` represents a black pixel and `.` represents a white pixel.  \n\n**Constraints**  \n1. $ 1 \\le T \\le 32 $  \n2. $ 1 \\le r_k, c_k \\le 1000 $ for all $ k $  \n3. Total number of pixels across all test cases $ \\le 5 \\times 10^6 $  \n4. Each connected component of `#` pixels corresponds to exactly one letter: 'H', 'M', or 'Y', with distinct topological structures.  \n\n**Objective**  \nFor each test case $ k $, count the number of connected components (under 8-connectivity) that correspond to the letters 'H', 'M', and 'Y', respectively, and output these three counts in order.","simple_statement":"Count the number of connected components of '#' that look like the letters 'H', 'M', and 'Y' in a grid. Each component is connected by edges or corners. Output three numbers: count of 'H', count of 'M', count of 'Y'.","has_page_source":false}