CF1634A.Reverse and Concatenate

传统题 时间 2000 ms 内存 256 MiB 3 尝试 1 已通过 1 标签

Reverse and Concatenate

Real stupidity beats artificial intelligence every time.— Terry Pratchett, Hogfather, Discworld

You are given a string ss of length nn and a number kk. Let's denote by rev(s)rev(s) the reversed string ss (i.e. rev(s)=snsn1...s1rev(s) = s_n s_{n-1} ... s_1). You can apply one of the two kinds of operations to the string:

  • replace the string ss with s+rev(s)s + rev(s)
  • replace the string ss with rev(s)+srev(s) + s

How many different strings can you get as a result of performing exactly kk operations (possibly of different kinds) on the original string ss?

In this statement we denoted the concatenation of strings ss and tt as s+ts + t. In other words, s+t=s1s2...snt1t2...tms + t = s_1 s_2 ... s_n t_1 t_2 ... t_m, where nn and mm are the lengths of strings ss and tt respectively.

Input

The first line contains one integer tt (1t1001 \le t \le 100) — number of test cases. Next 2t2 \cdot t lines contain tt test cases:

The first line of a test case contains two integers nn and kk (1n1001 \le n \le 100, 0k10000 \le k \le 1000) — the length of the string and the number of operations respectively.

The second string of a test case contains one string ss of length nn consisting of lowercase Latin letters.

Output

For each test case, print the answer (that is, the number of different strings that you can get after exactly kk operations) on a separate line.

It can be shown that the answer does not exceed 10910^9 under the given constraints.

Note

In the first test case of the example:

After the first operation the string ss can become either aabbaa or baaaab. After the second operation there are 2 possibilities for ss: aabbaaaabbaa and baaaabbaaaab.

Samples

4
3 2
aab
3 3
aab
7 1
abacaba
2 0
ab
2
2
1
1

在线编程 IDE

建议全屏模式获得最佳体验