#P16790. [蓝桥杯 2026 国 A] 魔法前缀

    ID: 19131 远端评测题 2000ms 512MiB 尝试: 0 已通过: 0 显示难度省选/NOI− 上传者: 标签>博弈论字典树 Trie2026蓝桥杯国赛SG 函数

[蓝桥杯 2026 国 A] 魔法前缀

Problem Description

XiaoLan and XiaoQiao jointly maintain a large dictionary. To free up storage space, they decide to delete unnecessary word prefixes through a “prefix pruning” magic game.

The dictionary contains NN words consisting of lowercase English letters.

Define the valid prefix set of the dictionary as the set of all non-empty prefixes of all words in the dictionary. Each identical prefix is kept only once. For example, if the dictionary contains only the words cat and car, then the valid prefix set is c, ca, cat, car.

The rules of the game are:

  1. XiaoLan and XiaoQiao take turns, with XiaoLan going first.
  2. On each turn, the current player must choose a non-empty prefix PP from the current valid prefix set.
  3. After choosing PP, all strings in the current set that have PP as a prefix will be deleted, including PP itself. For example, if the current valid prefix set is {\{"a", "ap", "app", "b", "ba"}\} and the player chooses "ap", then "ap" and "app" will both be deleted, and the set becomes {\{"a", "b", "ba"}\}.
  4. When it is a player’s turn, if the valid prefix set is empty, then that player loses the game.

Both players will use optimal strategies. Given the initial dictionary, determine who will win in the end.

Input Format

The first line contains an integer TT, indicating the number of test cases.

For each test case:

The first line contains an integer NN, indicating the number of words in the dictionary.

The next NN lines each contain a string consisting of lowercase English letters, representing a word.

Output Format

For each test case, output one line. If XiaoLan is guaranteed to win, output XiaoLan; otherwise output XiaoQiao.

2
2
ab
cd
2
cat
car
XiaoQiao
XiaoLan

Hint

Sample Explanation

In the first sample, the valid prefix set is a, ab, c, cd. The two branch structures are exactly the same. No matter which prefix XiaoLan chooses on one branch, XiaoQiao can make a symmetric move on the other branch, so XiaoQiao is guaranteed to win.

In the second sample, the valid prefix set is c, ca, cat, car. XiaoLan chooses c on the first move, which deletes the entire set and leaves XiaoQiao with no moves, so XiaoLan is guaranteed to win.

Constraints

For 30%30\% of the test cases, the total length of all strings in a single test case does not exceed 2020.

For all test cases, 1≤T≤101 \le T \le 10, 1≤N≤1051 \le N \le 10^5. The sum of string lengths over all test cases in a single input file does not exceed 10610^6. All strings contain only lowercase English letters.

Translated by ChatGPT 5