Hamzawy

No attempts yetTime limit1sMemory limit256 MB

Problem

Hamzawy was asked the following question in a programming interview and could not answer it, so solve it for him.

You are given a string SS of lowercase English letters. Find a string that is a prefix of SS, is a suffix of SS, and also appears once more as a substring of SS. The three occurrences must not overlap. Print the longest string that satisfies these conditions.

A prefix of a string SS is a string obtained by deleting zero or more characters from the end of SS. A suffix is a string obtained by deleting zero or more characters from the start of SS. A substring is a string obtained by deleting zero or more characters from the start of SS and zero or more characters from the end of SS.

Input

The first line contains the number of test cases TT. (1T1001 \le T \le 100)

Each of the next TT lines holds one test case: a non-empty string of lowercase English letters 'a' to 'z' whose length is at most 10610^6. The sum of the lengths of all strings in one input is at most 10610^6.

Output

For each test case print one line containing Case n:, then a single space, then the longest string that satisfies the conditions. Here nn is the test case number, starting from 11. If no such string exists, print -1 in place of the string.