#P1367E. Necklace Assembly
Necklace Assembly
No submission language available for this problem.
Description
The store sells 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:

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

In particular, a necklace of length is -beautiful for any integer . A necklace that consists of beads of the same color is also beautiful for any .
You are given the integers and , and also the string containing 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 -beautiful necklace you can assemble.
The first line contains a single integer () — the number of test cases in the test. Then test cases follow.
The first line of each test case contains two integers and ().
The second line of each test case contains the string containing lowercase English letters — the beads in the store.
It is guaranteed that the sum of for all test cases does not exceed .
Output answers to the test cases. Each answer is a positive integer — the maximum length of the -beautiful necklace you can assemble.
Input
The first line contains a single integer () — the number of test cases in the test. Then test cases follow.
The first line of each test case contains two integers and ().
The second line of each test case contains the string containing lowercase English letters — the beads in the store.
It is guaranteed that the sum of for all test cases does not exceed .
Output
Output answers to the test cases. Each answer is a positive integer — the maximum length of the -beautiful necklace you can assemble.
Samples
Note
The first test case is explained in the statement.
In the second test case, a -beautiful necklace can be assembled from all the letters.
In the third test case, a -beautiful necklace can be assembled, for example, from beads "abzyo".