CF BUDDY
← Problems·

1070J · Streets and Avenues in Berhattan

2300 · dp

Problem: Berhattan is the capital of Berland. There are nn streets running parallel in the east-west direction (horizontally), and there are mm avenues running parallel in the south-north direction (vertically). Each street intersects with each avenue, forming a crossroad. So in total there are nmn \cdot m crossroads in Berhattan.

Recently, the government has changed in Berland. The new government wants to name all avenues and all streets after heroes of revolution.

The special committee prepared the list of kk names. Only these names can be used as new names for streets and avenues. Each name can be used at most once.

The members of committee want to name streets and avenues in the way that minimizes inconvenience for residents. They believe that if street and avenue names start with the same letter, then their crossroad will be inconvenient. Hence only the first letter of each name matters.

Given first letters of kk names, find CC — minimal possible number of inconvenient crossroads in Berhattan after the naming process.

Input Format: Input contains one or several test cases to process. The first line contains tt (1t300001 \le t \le 30000) — the number of test cases. Solve test cases separately, test cases are completely independent and do not affect each other.

The description of tt test cases follows. Each test case starts with line with space-separated numbers n,m,kn, m, k (1n,m300001 \le n,m \le 30000; n+mk2105n+m \le k \le 2\cdot10^5) — the number of streets, number of avenues and the number of names in the committee's list, respectively.

The the second line of each test case contains a string of kk uppercase English letters. ii-th letter of the string is the first letter of ii-th name from the committee's list.

It's guaranteed that the sum of numbers nn from all test cases is not greater than 3000030000. Similarly, the sum of numbers mm from all test cases is not greater than 3000030000. The sum of numbers kk from all test cases is not greater than 21052\cdot10^5.

Output Format: For each test case print single number CC in the separate line — minimal possible number of inconvenient crossroads in Berhattan after the naming process.

Sample Cases

Case 1

Input

2
2 3 9
EEZZEEZZZ
2 7 9
EEZZEEZZZ

Output

0
4

Case 2

Input

2
4 4 8
CZBBCZBC
1 1 4
TTCT

Output

1
0

Similar problems

00:00:00
Loading editor…
Welcome! I'm your coding tutor for this problem. Use the chips below to reveal stored hints or get AI feedback on your code. I'll guide you step by step — never giving away the solution.

Sign in to unlock AI tutor feedback