#P1367E. Necklace Assembly

    ID: 1458 Type: RemoteJudge 2000ms 256MiB Tried: 0 Accepted: 0 Difficulty: (None) Uploaded By: Tags>brute forcedfs and similardpgraphsgreedynumber theory*1900

Necklace Assembly

No submission language available for this problem.

Description

The store sells nn beads. The color of each bead is described by a lowercase letter of the English alphabet ("a"–"z"). You want to buy some beads to assemble a necklace from them.

A necklace is a set of beads connected in a circle.

For example, if the store sells beads "a", "b", "c", "a", "c", "c", then you can assemble the following necklaces (these are not all possible options):

And the following necklaces cannot be assembled from beads sold in the store:

The first necklace cannot be assembled because it has three beads "a" (of the two available). The second necklace cannot be assembled because it contains a bead "d", which is not sold in the store.

We call a necklace kk-beautiful if, when it is turned clockwise by kk beads, the necklace remains unchanged. For example, here is a sequence of three turns of a necklace.

As you can see, this necklace is, for example, 33-beautiful, 66-beautiful, 99-beautiful, and so on, but it is not 11-beautiful or 22-beautiful.

In particular, a necklace of length 11 is kk-beautiful for any integer kk. A necklace that consists of beads of the same color is also beautiful for any kk.

You are given the integers nn and kk, and also the string ss containing nn lowercase letters of the English alphabet — each letter defines a bead in the store. You can buy any subset of beads and connect them in any order. Find the maximum length of a kk-beautiful necklace you can assemble.

The first line contains a single integer tt (1t1001 \le t \le 100) — the number of test cases in the test. Then tt test cases follow.

The first line of each test case contains two integers nn and kk (1n,k20001 \le n, k \le 2000).

The second line of each test case contains the string ss containing nn lowercase English letters — the beads in the store.

It is guaranteed that the sum of nn for all test cases does not exceed 20002000.

Output tt answers to the test cases. Each answer is a positive integer — the maximum length of the kk-beautiful necklace you can assemble.

Input

The first line contains a single integer tt (1t1001 \le t \le 100) — the number of test cases in the test. Then tt test cases follow.

The first line of each test case contains two integers nn and kk (1n,k20001 \le n, k \le 2000).

The second line of each test case contains the string ss containing nn lowercase English letters — the beads in the store.

It is guaranteed that the sum of nn for all test cases does not exceed 20002000.

Output

Output tt answers to the test cases. Each answer is a positive integer — the maximum length of the kk-beautiful necklace you can assemble.

Samples

Sample Input 1

6
6 3
abcbac
3 6
aaa
7 1000
abczgyo
5 4
ababa
20 10
aaebdbabdbbddaadaadc
20 5
ecbedececacbcbccbdec

Sample Output 1

6
3
5
4
15
10

Note

The first test case is explained in the statement.

In the second test case, a 66-beautiful necklace can be assembled from all the letters.

In the third test case, a 10001000-beautiful necklace can be assembled, for example, from beads "abzyo".