CF2039B.Shohag Loves Strings

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

Shohag Loves Strings

For a string pp, let f(p)f(p) be the number of distinct non-empty substrings^{\text{∗}} of pp.

Shohag has a string ss. Help him find a non-empty string pp such that pp is a substring of ss and f(p)f(p) is even or state that no such string exists.

^{\text{∗}}A string aa is a substring of a string bb if aa can be obtained from bb by deletion of several (possibly, zero or all) characters from the beginning and several (possibly, zero or all) characters from the end.

Input

The first line contains a single integer tt (1t1041 \le t \le 10^4) — the number of test cases.

The first and only line of each test case contains a string ss (1s1051 \le |s| \le 10^5) consisting of lowercase English letters.

It is guaranteed that the sum of the length of ss over all test cases doesn't exceed 31053 \cdot 10^5.

Output

For each test case, print a non-empty string that satisfies the conditions mentioned in the statement, or 1-1 if no such string exists. If there are multiple solutions, output any.

Note

In the first test case, we can set p=p = abaa because it is a substring of ss and the distinct non-empty substrings of pp are a, b, aa, ab, ba, aba, baa and abaa, so it has a total of 88 distinct substrings which is even.

In the second test case, we can only set p=p = a but it has one distinct non-empty substring but this number is odd, so not valid.

In the third test case, the whole string contains 5252 distinct non-empty substrings, so the string itself is a valid solution.

Samples

5
dcabaac
a
youknowwho
codeforces
bangladesh
abaa
-1
youknowwho
eforce
bang

在线编程 IDE

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