This problem is an adapted Mooshak version of a UVA Online Judge Problem.


[PC038] Rank the Languages

You might have noticed that English and Spanish are spoken in many areas all over the world. Now it would be nice to rank all languages according to the number of states where they are spoken.

You’re given a map which shows the states and the languages where they are spoken. Look at the following map:

ttuuttdd
ttuuttdd
uuttuudd
uuttuudd

The map is read like this: Every letter stands for a language and states are defined as connected areas with the same letter. Two letters are "connected" if one is at left, at right, above or below the other one. So in the above map, there are three states where the language "t" is spoken, three where "u" is spoken and one state where people speak "d".

The Problem

Your job is to determine the number of states for each language and print the results in a certain order.

Input

The first line contains the number of test cases \(N\). Each test case consists of a line with two numbers \(H\) and \(W\) , which are the height and the width of the map. Then follow \(H\) lines with a string of \(W\) letters. Those letters will only be lowercase letters from 'a' to 'z'

Output

For each test case print "World #n", where \(n\) is the number of the test case. After that print a line for each language that appears in the test case, which contains the language, a colon, a space and the number of states, where that language is spoken. These lines have to be ordered decreasingly by the number of states. If two languages are spoken in the same number of states, they have to appear alphabetically, which means language ‘i’ comes before language ‘q’, for example

Constraints

The following limits are guaranteed in all the test cases that will be given to your program:

\(1 \leq N \leq 10\)       Number of words
\(1 \leq H,W \leq 200\)       Height and width of map

Example Input Example Output
2
4 8
ttuuttdd
ttuuttdd
uuttuudd
uuttuudd
9 9
bbbbbbbbb
aaaaaaaab
bbbbbbbab
baaaaacab
bacccccab
bacbbbcab
bacccccab
baaaaaaab
bbbbbbbbb
World #1
t: 3
u: 3
d: 1
World #2
b: 2
a: 1
c: 1


Competitive Programming (CC3032) 2025/2026
DCC/FCUP - University of Porto