Universal Cup Judging System

Universal Cup

Time Limit: 4.0 s Memory Limit: 1024 MB Total points: 100 Hackable ✓
Statistics

Putata 带来了他最新的字符串问题。给定两个字符串序列 $A$ 和 $B$,每个序列恰好包含 $n$ 个字符串,且所有字符串的长度均为 $m$。你需要重新排列这些字符串,使得两个序列中所有字符串拼接后的结果循环同构。

形式化地,你需要选择两个 $1, 2, \dots, n$ 的排列 $p$ 和 $q$,使得 $A_{p_1} + A_{p_2} + \dots + A_{p_n}$ 与 $B_{q_1} + B_{q_2} + \dots + B_{q_n}$ 循环同构。字符串 $R = S + T$ 满足:对于 $i \le |S|$,$R_i = S_i$,否则 $R_i = T_{i-|S|}$。称两个字符串 $S, T$ 循环同构,当且仅当存在整数 $d$,使得对于所有 $1 \le i \le |S|$,都有 $S_i = T_{((i+d) \pmod{|S|}) + 1}$,且 $|S| = |T|$。

请帮助 Budada 找到 $p$ 和 $q$,或者报告不存在这样的 $p$ 和 $q$。

输入格式

第一行包含一个整数 $t$ ($1 \le t \le 10^6$),表示测试用例的数量。

对于每个测试用例,第一行包含两个整数 $n, m$ ($1 \le n, m \le 10^6, 1 \le n \cdot m \le 10^6$)。

接下来 $n$ 行,第 $i$ 行包含一个字符串 $A_i$ ($|A_i| = m$)。

接下来 $n$ 行,第 $i$ 行包含一个字符串 $B_i$ ($|B_i| = m$)。

保证所有输入字符串仅包含小写英文字母。

保证所有测试用例中 $n \cdot m$ 的总和不超过 $10^6$。

输出格式

对于每个测试用例,如果排列 $p$ 和 $q$ 存在,请分两行输出它们,排列中的元素用空格分隔。否则,输出 $-1$。

样例

样例输入 1

2
3 3
abc
ghi
def
bcd
efg
hia
1 3
abc
def

样例输出 1

1 3 2
1 2 3
-1

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.