CF1360F.Spy-string

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

You are given nn strings a1,a2,,ana_1, a_2, \ldots, a_n : all of them have the same length mm . The strings consist of lowercase English letters.

Find any string ss of length mm such that each of the given nn strings differs from ss in at most one position. Formally, for each given string aia_i , there is no more than one position jj such that ai[j]s[j]a_i[j] \ne s[j] .

Note that the desired string ss may be equal to one of the given strings aia_i , or it may differ from all the given strings.

For example, if you have the strings abac and zbab, then the answer to the problem might be the string abab, which differs from the first only by the last character, and from the second only by the first.

输入格式

The first line contains an integer tt ( 1t1001 \le t \le 100 ) — the number of test cases. Then tt test cases follow.

Each test case starts with a line containing two positive integers nn ( 1n101 \le n \le 10 ) and mm ( 1m101 \le m \le 10 ) — the number of strings and their length.

Then follow nn strings aia_i , one per line. Each of them has length mm and consists of lowercase English letters.

输出格式

Print tt answers to the test cases. Each answer (if it exists) is a string of length mm consisting of lowercase English letters. If there are several answers, print any of them. If the answer does not exist, print "-1" ("minus one", without quotes).

输入输出样例

  • 输入#1

    5
    2 4
    abac
    zbab
    2 4
    aaaa
    bbbb
    3 3
    baa
    aaa
    aab
    2 2
    ab
    bb
    3 1
    a
    b
    c

    输出#1

    abab
    -1
    aaa
    ab
    z

说明/提示

The first test case was explained in the statement.

In the second test case, the answer does not exist.

首页