For each board, pick the single column to turn entirely black that maximizes the total number of same-color connected regions, breaking ties by more white regions.
Medium6GraphDFSImplementationBrute forceNo attempts yetTime limit2sMemory limit512 MBNarwhy the narwhal likes playing games on his waterproof phone. He recently downloaded a new game from the OceanStore. The game shows a rectangular board made of white and black squares. The tutorial taught him that touching any column turns that whole column black. The more same color regions the board has, the higher his score.
![]() | ![]() | ![]() | ![]() |
| Original board | Column 1 touched | Column 2 touched | Column 3 touched |
A region is a maximal set of squares of the same color that are connected to one another. Two squares are connected when they share an edge. After playing for a while, Narwhy also noticed that between two boards with the same number of regions in total, the one with more white regions scores higher. Given the state of a board, find the highest score Narwhy can reach by touching exactly one column.

The first line contains the number of data sets P (1≤P≤10000). Every data set is independent and is processed the same way.
Each data set uses two or more lines. Its first line contains the data set number K, a single space, then the number of rows N and the number of columns M (1≤N,M≤1000). Each of the next N lines contains a string of M characters, where 0 is a white square and 1 is a black square.
Print one line for each data set. The line contains the data set number K, a space, then the number of white regions and the number of black regions, separated by a space, on the board with the highest score that touching exactly one column can produce.
A board scores higher when it has more regions in total. When two boards have the same total, the one with more white regions scores higher.