Technocup 2022 - Elimination Round 2
F
Strange LCS
Codeforces
2600
原题
← EG →
翻译中…

You are given $n$ strings $s_1, s_2, \ldots, s_n$, each consisting of lowercase and uppercase English letters. In addition, it's guaranteed that each character occurs in each string at most twice. Find the longest common subsequence of these strings.

翻译中…

A string $t$ is a subsequence of a string $s$ if $t$ can be obtained from $s$ by deletion of several (possibly, zero or all) symbols.

翻译中…

Input

翻译中…

Each test consists of multiple test cases. The first line contains a single integer $t$ ($1 \leq t \leq 5$) — the number of test cases. Description of the test cases follows.

翻译中…

The first line of each test case contains a single integer $n$ ($2 \leq n \leq 10$) — the number of strings.

翻译中…

Each of the next $n$ lines contains the corresponding string $s_i$. Each $s_i$ is non-empty, consists only of uppercase and lowercase English letters, and no character appears more than twice in each string.

翻译中…

Output

翻译中…

For each test case print the answer in two lines:

翻译中…

In the first line print the length of the longest common subsequence.

翻译中…

In the second line print the longest common subsequence. If there are multiple such subsequences, print any of them.

翻译中…

Note

翻译中…

In the first test case, the longest common subsequence is "A". There are no common subsequences of length $2$.

翻译中…

In the second test case, sets of characters of strings don't intersect, so any non-empty string can't be a common subsequence.

翻译中…

样例

Input #1
4
2
ABC
CBA
2
bacab
defed
3
abcde
aBcDe
ace
2
codeforces
technocup
Output #1
1
A
0

3
ace
3
coc
InputCopy OutputCopy
题目信息
题号
1584F
时间限制
2 s
内存限制
256 MB
标签
位运算
动态规划
图论
贪心
字符串

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