#P5433. 月宫的符卡序列

月宫的符卡序列

Background

Problem Description

Update: Two sets of testdata have been rebuilt, and the testdata has been strengthened.

Kaguya was originally a princess of the Moon who lived in the Moon Palace.

When Kaguya was cleaning the warehouse of Eientei, she found an ancient spell card sequence SS. It might have been created a very, very long time ago, when Kaguya still lived in the Moon Palace, but now she cannot remember it anymore.

So Kaguya decided to study this spell card sequence. The spell cards in SS are indexed starting from 00. Also, when she created it, the deck size did not exceed 2626, so each spell card is represented by a letter from aa to zz.

Kaguya is very interested in sequences that read the same from left to right and from right to left. For any contiguous subsequence aa of SS that satisfies the above condition, its value is defined as the XOR of the midpoints of all occurrences of aa in SS (that is, if aa occurs at l...rl...r, then the midpoint is l+r2\lfloor \frac{l+r}{2} \rfloor).

Kaguya wants to know, among all such aa, what the maximum value is.

Input Format

The first line contains an integer numnum (5\le 5), indicating the number of test cases.

Each test case consists of one line containing a string SS with only lowercase letters, representing the spell card sequence.

Output Format

For each test case, output one line representing the answer Kaguya wants to know.

1
aabacabaaa
15

Hint

1S1061 \le |S| \le 10^6

Translated by ChatGPT 5