SCCHEM - Strongly Connected Chemicals

Giới hạn
  • Thời gian: 1.0s
  • Bộ nhớ: 1536MB
  • Mã nguồn: 50000 bytes

Ghi chú: Các bài VNOI đã được chuyển qua VNOJ (Thông báo). Đề bài trên VNOI và vn.spoj.com sẽ không được cập nhật nữa. Một số đề bài không chính xác sẽ chỉ được cập nhật trên VNOJ. Bạn vẫn có thể tìm kiếm đề bài trên VNOI.

Link đọc đề trên VNOJ

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 j th character in the i th line is 1 , that means the i th cation attracts the j th 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
2
3 4
1100
1110
0011
2 2
10
00

Sample Output
Case 1: 4
Case 2: 2

 


  • Người up: racer