Codeforces Round 1078 (Div. 2)
C
Secret message
Codeforces
1300
原题
← BD →
翻译中…

Bob, the genius spy, has intercepted an encrypted message. He assumes that it contains secret information and is actively engaged in deciphering it.

翻译中…

The note, which has fallen into the hands of the spy, consists of $k$ strips, each of length $n$ and containing strict lowercase Latin letters. With extensive experience in deciphering such documents, Bob guessed that the message he is interested in (the deciphering of the note) is also a string of length $n$, and the $i$-th letter of this message corresponds to the $i$-th letter of one of the strips.

翻译中…

According to Bob, the informativity of a string $s$ is defined as the minimum positive integer $d$ such that a string $t$ of length $d$ exists, and $s$ can be formed by repeating $t$ several times. For example, the informativity of the string "aaaa" is 1, the informativity of the string "abab" is 2, and the informativity of the string "abcd" is 4.

翻译中…

Bob assumes that the note's author, to ensure reliable transmission of information, repeated the data in the message several times. Therefore, he believes that a more plausible decryption of the note would have the smallest possible informativity.

翻译中…

Help the spy: find the message that represents the decryption of the note and has the minimum possible informativity.

翻译中…

Input

翻译中…

Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 10^4$). The description of the test cases follows.

翻译中…

In the first line of each test case, there are numbers $n$ and $k$ ($2 \leq n, k \leq 50\,000, 4 \leq n \cdot k \leq 10^5$) — the length of the strips of paper and the number of strips.

翻译中…

In each of the following $k$ lines of each test case, there is a sequence of $n$ lowercase Latin letters — the next strip.

翻译中…

It is guaranteed that the sum $n \cdot k$ across all test cases does not exceed $10^5$

翻译中…

Output

翻译中…

For each test case, output a string of length $n$ — the decryption of the note, which has the minimal possible informativity. If there are multiple suitable answers, any of them may be output.

翻译中…

Note

翻译中…

In the first test case, the minimum possible informativity is $1$:

翻译中…

abc

翻译中…

baa

翻译中…

In the second test case, the minimum possible informativity is $3$:

翻译中…

iiinnnfff

翻译中…

nnfiffinn

翻译中…

样例

Input #1
3
3 2
abc
baa
9 2
iiinnnfff
nnfiffinn
4 2
acbd
bdac
Output #1
aaa
infinfinf
acac
InputCopy OutputCopy
题目信息
题号
2194C
时间限制
2 s
内存限制
256 MB
标签
位运算
暴力
动态规划
数学
数论

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。