| Due to a convenient recent teaching vacancy, Laz Y. has suddenly landed a job |
| as a schoolteacher. Known to his students as Mr. Y, he's prepared to provide a |
| comprehensive, fairly-evaluated educational experience — as long as it doesn't |
| take too much effort. |
|
|
| Mr. Y's first order of business in his new role will be grading recent exams |
| from two different subjects: art and biology. He has been handed **S** stacks |
| of **H** exam papers each. The _i_th paper from the top in the _j_th stack is |
| either from the art exam (if **Pi,j** = "A"), or otherwise from the biology |
| exam (if **Pi,j** = "B"). |
|
|
| Mr. Y will go about the grading process as follows: At each point in time, |
| he'll select a stack which still contains at least one exam paper, and remove |
| its topmost paper. He'll then either grade that paper, or accidentally "lose" |
| it and assign its owner a random grade instead. Either way, once he's done |
| with that paper, he'll repeat the process of selecting a new paper until all |
| of the stacks are empty and all **H*****S** papers have been dealt with. |
| |
| There are few things that Mr. Y hates as much as context switching. For |
| example, it's very troublesome to jump from grading an art exam to a biology |
| one! (Or from relaxing to doing any work at all.) Each time Mr. Y begins a |
| grading a paper, he must make a context switch if this is either the first |
| paper he's choosing to grade, or if its subject is different than that of the |
| previous paper that he graded. Note that this entirely excludes any "lost" |
| papers. |
| |
| Mr. Y is no fool — he realizes that his evaluations would be too suspiciously |
| inaccurate if he were to simply lose all **H*****S** papers. Even losing a |
| smaller number of them may prove too suspicious. Therefore, he'll imagine |
| **K** different theoretical scenarios, such that in the _i_th one, he will |
| allow himself to lose at most **Li** papers throughout the grading process |
| (with **L1..K** all being distinct). Independently for each scenario, he'd |
| like to determine the minimum number of context switches he would need to make |
| throughout the process. |
|
|
| ### Input |
|
|
| Input begins with an integer **T**, the number of days Mr. Y spends grading |
| exams. For each day, there is first a line containing the space-separated |
| integers **H**, **S**, and **K**. Then, **H** lines follow, the _i_th of which |
| contains the length-**S** string **Pi,1..S**. Then, a final line follows |
| containing the **K** space-separated integers **L1** through **LK**. |
|
|
| ### Output |
|
|
| For the _i_th day, print a line containing "Case #_i_: " followed by **K** |
| space-separated integers, the _j_th of which is the minimum number of context |
| switches which Mr. Y would need to make if he were to grade the papers while |
| losing at most **Lj** of them. |
|
|
| ### Constraints |
|
|
| 1 ≤ **T** ≤ 200 |
| 1 ≤ **H**, **S** ≤ 300 |
| 1 ≤ **K** ≤ **H** * **S** |
| 0 ≤ **Li** ≤ **H** * **S** \- 1 |
|
|
| ### Explanation of Sample |
|
|
| In the first case, if Mr. Y may only lose one paper, the best he can do is |
| make two context switches, for example by grading the B papers from the first |
| and third stacks, then losing the B paper from the fifth stack, and then |
| grading the A papers from the second and fourth stacks. On the other hand, the |
| freedom to lose two papers would allow him to make only one context switch, |
| for example by losing the A papers from the second and fourth stacks and then |
| grading the B papers from the first, third, and fifth stacks. |
|
|
| In the second case, if Mr. Y may lose one paper, one optimal strategy |
| (requiring just two context switches) is as follows: |
|
|
| 1. Grade the B paper from the top of stack 2 (first context switch). |
| 2. Lose the A paper from the top of stack 3. |
| 3. Grade the B paper from the top of stack 3. |
| 4. Grade the A paper from the top of stack 1 (second context switch). |
| 5. Grade the A paper from the top of stack 1. |
| 6. Grade the A paper from the top of stack 2. |
|
|
|
|