SCCHEM - Strongly Connected Chemicals

no tags 

One type of chemical compounds is the ionic compound, because it is composed of positively charged ions (cations) and negatively charged ions (anions) in such a way that the compound as a whole is electrically neutral. Cations always attract anions and anions always attract cations.

Now you are given m cations and n anions, and their connectivity information about which cation attracts which anion. You task is to find a sub group from the cations and anions where there is at least one cation and at least one anion, such that all the cations in the group attract all the anions in the group. We call such a group as 'Strongly Connected Chemicals'. As there can be many such groups, we want to find a group which has the highest cardinality. Cardinality means the number of members (cation and anion) in the group.

Input

Input starts with an integer T (≤ 100), denoting the number of test cases.

Each case starts with a line containing two integers: m and n (1 ≤ m, n ≤ 50). Each of the next m lines contains n characters (without space), each either '0' or '1'. If the jth character in the ith line is 1, that means the ith cation attracts the jth anion, otherwise it doesn't.

Output

For each case, print the case number and the maximum possible size of the strongly connected chemical group.

Sample Input

Output for Sample Input

2

3 4

1100

1110

0011

2 2

10

00

Case 1: 4

Case 2: 2

 



Added by:Race with time
Date:2012-11-06
Time limit:1s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: ASM64