CF BUDDY
← Problems·

1995D · Cases

2300 · bitmasks, brute force, dp

Problem: You're a linguist studying a mysterious ancient language. You know that

  1. Its words consist only of the first cc letters of the Latin alphabet.
  2. Each word has a case which can be unambiguously determined by its last letter (different letters correspond to different cases). For example, words "ABACABA" and "ABA" (if they exist) have the same case in this language because they both have the same ending 'A', whereas "ALICE" and "BOB" have different cases. If the language does not have a case corresponding to some letter, it means that the word cannot end with this letter.
  3. The length of each word is kk or less.

You have a single text written in this language. Unfortunately, as the language is really ancient, spaces between words are missing and all letters are uppercase. You wonder what is the minimum number of cases the language can have. Can you find this out?

Input Format: Each test consists of several test cases. The first line contains a single integer tt (1t100001 \le t \le 10\,000) — the number of test cases. It is followed by descriptions of the test cases.

The first line of each test case contains three integers nn, cc, kk (1kn2181 \le k \le n \le 2^{18}, 1c181 \le c \le 18) — the length of the text, the number of letters in the language, and the maximum length of the word.

The second line contains a string of nn characters — the text itself. Each character is one of the first cc uppercase letters of the Latin alphabet.

It is guaranteed that the sum of nn over all test cases does not exceed 2182^{18} and the sum of 2c2^c over all test cases does not exceed 2182^{18}.

Output Format: For each test case, output a single line consisting of a single integer — the minimum number of cases in the language.

Note: In the first test case, there must be five cases in the language (for each of the letters 'A', 'B', 'C', 'D', and 'E' there must be a case that has a corresponding ending).

In the fourth test case, one case with ending 'B' is sufficient.

Sample Cases

Case 1

Input

7
5 5 1
ABCDE
3 1 2
AAA
3 2 2
AAB
10 2 2
ABABABABAB
4 4 4
DCBA
1 17 1
Q
9 3 2
ABCABCABC

Output

5
1
2
1
1
1
2

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