atcoder#ARC155A. [ARC155A] ST and TS Palindrome

[ARC155A] ST and TS Palindrome

Score : 400400 points

Problem Statement

You are given a string SS of length NN consisting of lowercase English letters, and a positive integer KK.

Determine whether there is a string SS' of length KK that satisfies the following conditions.

  • The concatenation of SS and SS' in this order is a palindrome.
  • The concatenation of SS' and SS in this order is a palindrome.

You have TT test cases to solve.

Constraints

  • 1T1051 \leq T \leq 10^5
  • 1N2×1051 \leq N \leq 2 \times 10^5
  • 1K10181 \leq K \leq 10^{18}
  • SS is a string of length NN consisting of lowercase English letters.
  • All numbers in the input are integers.
  • In each input file, the sum of NN over the test cases is at most 2×1052 \times 10^5.

Input

The input is given from Standard Input in the following format:

TT

case1\mathrm{case}_1

\vdots

caseT\mathrm{case}_T

Each case is in the following format:

NN KK

SS

Output

Print TT lines. The ii-th line should contain Yes if there is a string SS' that satisfies the conditions for the ii-th test case, and No otherwise.

2
6 2
abbaab
5 3
abcbb
Yes
No

For the first test case, if we let S=S' = {}ba, for instance, the concatenation of SS and SS' in this order will be abbaabba, which is a palindrome. Here, the concatenation of SS' and SS in this order is baabbaab, which is also a palindrome. Thus, S=S' = {}ba satisfies the condition, so the answer is Yes.

For the second test case, we can prove that no string satisfies the conditions.

3
12 400378271514996652
njvhhvjnnjvh
10 884633988115575508
rrhiyvrrur
36 71630165869626180
vsxmxajrrduhhudrrjaxmxsvvsxmxajrrduh
Yes
No
Yes