TopCoder

User's AC Ratio

NaN% (0/0)

Submission's AC Ratio

NaN% (0/0)

Tags

Description


Palindrome is a string that can be read in the same way in either forward or backward direction. For example: ABBA is a palindrome, MOM is also a palindrome, but MATE is not. A non-palindrome string can be transformed into a palindrome by changing some of its characters. We call a string a k
-palindrome if it can be turned into a palindrome by changing at most k
characters. By this definition, a regular palindrome string is 0-palindrome.

Given a string S
of length N
that contains only lowercase characters (`a'...
'z') and an integer k

, find the longest substring of S
which is k
-palindrome.

Input Format


The first line of the input contains an integer T

, the number of test cases to follow. Each case consists of string S
<!-- MATH
$(1 \le |S| \le 1000)$
-->
(1 WIDTH="18" HEIGHT="31" ALIGN="MIDDLE" BORDER="0"
SRC="/ntujudge/problemdata/634.png"
ALT="$ \le$">| S| WIDTH="18" HEIGHT="31" ALIGN="MIDDLE" BORDER="0"
SRC="/ntujudge/problemdata/634.png"
ALT="$ \le$">1000)

and integer K
<!-- MATH
$(0 \le K \le |S|)$
-->

(0 WIDTH="18" HEIGHT="31" ALIGN="MIDDLE" BORDER="0"
SRC="/ntujudge/problemdata/634.png"
ALT="$ \le$">K WIDTH="18" HEIGHT="31" ALIGN="MIDDLE" BORDER="0"
SRC="/ntujudge/problemdata/634.png"
ALT="$ \le$">| S|)

. String S
consists of lowercase characters (<TT>a</TT>' <SPAN CLASS="MATH">...</SPAN>
<tex2html_verbatim_mark>
z') only. | S|

denotes the length of string S
.

Output Format


For each case, print in a single line: the length of the longest substring of S
which is k

-palindrome.

Sample Input 1



3
abba 0
mate 1
zabcddcbxy 1



Sample Output 1



4
3
8



Hints

Problem Source

Migrated from old NTUJ.

ACM ICPC regional Jakarta site 2008

Subtasks

No. Testdata Range Score

Testdata and Limits

No. Time Limit (ms) Memory Limit (VSS, KiB) Output Limit (KiB) Subtasks
0 10000 65536 200