Its year 3000, and the voting system in Ajobdesh has changed to a new era. Instead of the boring old style voting, the new style voting is applied as follows:
- Initially there are m male candidates and f female candidates for the parliament. For simplicity the male candidates are numbered as 'M1', 'M2' ... 'Mm' and the female candidates are numbered as 'F1', 'F2' ... 'Ff'.
- There are v voters, and each of them can vote like 'P Q', which means, he wants to see P in the parliament and he wants Q to be thrown out of the parliament. For example, if a person voted like, 'M3 F7', that means he wants M3 to be elected and F7 to be thrown out.
- The parliament will be formed in such a way that the maximum number of votes is satisfied. A voter, who voted 'P Q', is said to be satisfied if P is in the parliament and Q is not. For example, let the parliament be {M1, M3, F3}, then voter who voted 'M1 F4' is satisfied but neither of 'M1 F3', 'F3 M3' or 'M2 F3' is satisfied.
Since you are the leading programmer in Ajobdesh, you have to form the parliament such that maximum number of voters is satisfied. Just report the maximum number of satisfied voters.
Input
Input starts with an integer T (≤ 25), denoting the number of test cases.
Each case starts with a line containing three integers: m, f, v (1 ≤ m, f ≤ 100, 0 ≤ v ≤ 500). Each of the next v lines contains a vote either in the form 'Mx Fy' or 'Fy Mx' (1 ≤ x ≤ m, 1 ≤ y ≤ f).
Output
For each case, print the case number and the maximum number of satisfied voters.
Sample
Sample Input | Sample Output |
---|---|
2 1 1 2 M1 F1 F1 M1 1 2 5 M1 F1 M1 F1 M1 F2 F2 M1 F1 M1 | Case 1: 1 Case 2: 3 |