#P16887. [GKS 2022 #E] Matching Palindrome

[GKS 2022 #E] Matching Palindrome

Problem Description

You are given a palindrome string PP of length NN consisting of only lowercase letters of the English alphabet. Find the shortest non-empty palindrome string QQ such that PP concatenated with QQ forms a palindrome. Formally, the string PQPQ forms a palindrome.

Input Format

The first line of the input gives the number of test cases, TT. TT test cases follow. Each test case consists of 22 lines. The first line of each test case contains an integer NN denoting the length of the string PP. The second line of each test case contains a palindrome string PP of length NN.

Output Format

For each test case, output one line containing Case #xx: yy, where xx is the test case number starting from 11 and yy is the non-empty palindrome string QQ as described above.

3
4
abba
4
cccc
6
cdccdc
Case #1: abba
Case #2: c
Case #3: cdc

Hint

In Case 11, the shortest palindrome string QQ is abba such that the concatenation PQPQ is abbaabba, which is a palindrome.

In Case 22, the shortest palindrome string QQ is c such that the concatenation PQPQ is ccccc, which is a palindrome.

In Case 33, the shortest palindrome string QQ is cdc such that the concatenation PQPQ is cdccdccdc, which is a palindrome.

Limits

1T1001 \le T \le 100.

String PP is a palindrome consisting of only lowercase letters of the English alphabet.

Test Set 1

1N1031 \le N \le 10^3.

Test Set 2

1N1051 \le N \le 10^5.