Codeforces Round #644 (Div. 3) F.Spy-string

题目链接

You are given n strings a1,a2,…,an: all of them have the same length m. The strings consist of lowercase English letters.

Find any string s of length m such that each of the given n strings differs from s in at most one position. Formally, for each given string ai, there is no more than one position j such that ai[j]≠s[j].

Note that the desired string s may be equal to one of the given strings ai, 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.

Input

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

Each test case starts with a line containing two positive integers n (1≤n≤10) and m (1≤m≤10) — the number of strings and their length.

Then follow n strings ai, one per line. Each of them has length m and consists of lowercase English letters.

Output

Print t answers to the test cases. Each answer (if it exists) is a string of length m 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).

Example

input

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

output

abab
-1
aaa
ab
z

字符串水题~
我们观察一下数据直接确定用暴力

Codeforces Round #644 (Div. 3) F.Spy-string相关推荐

  1. Codeforces Round #797 (Div. 3) F. Shifting String题解

    题意是给一个字符串s和一个与之相同长度的数组排列a,字符串s按照数组给定的位置进行变化,新字符串的第i个字符是上一个字符串的第a[i]个字符 比如 例子 5 ababa 2 1 4 5 3 变化6次 ...

  2. Codeforces Round #699 (Div. 2) F - AB Tree(贪心、树上DP)超级清晰,良心题解,看不懂来打我 ~

    整理的算法模板合集: ACM模板 点我看算法全家桶系列!!! 实际上是一个全新的精炼模板整合计划 Codeforces Round #699 (Div. 2) F - AB Tree Problem ...

  3. Codeforces Round #644 (Div. 3) E.Polygon

    Codeforces Round #644 (Div. 3) E.Polygon 题目链接 Polygon is not only the best platform for developing p ...

  4. Codeforces Round #644 (Div. 3) D.Buying Shovels

    Codeforces Round #644 (Div. 3) D.Buying Shovels 题目链接 Polycarp wants to buy exactly n shovels. The sh ...

  5. Codeforces Round #644 (Div. 3) G.A/B Matrix

    Codeforces Round #644 (Div. 3) G.A/B Matrix 题目链接 You are given four positive integers n, m, a, b (1≤ ...

  6. Codeforces Round #849 (Div. 4) F. Range Update Point Query

    Codeforces Round #849 (Div. 4) F. Range Update Point Query 题目大意: 给一串数字,有两个操作: 操作1:将 l − r l-r l−r 的数 ...

  7. Codeforces Round #656 (Div. 3) D. a-Good String

    Codeforces Round #656 (Div. 3) D. a-Good String 题目链接 You are given a string s[1-n] consisting of low ...

  8. Codeforces Round #538 (Div. 2) F. Please, another Queries on Array? 线段树 + 欧拉函数

    传送门 文章目录 题意: 思路: 题意: 给你一个序列aaa,你需要实现两种操作: (1)(1)(1) 将[l,r][l,r][l,r]的aia_iai​都乘rrr. (2)(2)(2) 求ϕ(∏i= ...

  9. Codeforces Round #742 (Div. 2) F. One-Four Overload 构造 + 二分图染色

    传送门 文章目录 题意: 思路: 题意: 给你一个n∗mn*mn∗m的矩形,包含...和XXX,你有两种颜色,你需要给...染色使得每个XXX上下左右相邻的...其两种颜色个数相同,输出一种合法方案. ...

最新文章

  1. TEASOFT辅助服务程序UDPCopy 功能介绍
  2. 图像传感器与信号处理——详解CCD与CMOS图像传感器
  3. 在与 SQL Server 建立连接时出现与网络相关的或特定于实例的错误。未找到或无法访问服务器(及Windows 10无法找到SQL server配置管理器的解决方法)
  4. tinymce 工具栏 不显示_winform中MenuStrip主菜单、工具栏、状态栏、托盘、其他控件...
  5. 心血来潮,小试c++11
  6. 《机器学习实战》程序清单4-2 朴素贝叶斯分类器训练函数
  7. 理解Dubbo的调用流程与Dubbo多协议解析
  8. [转载] Python正则表达式(含正则表达式速查表)
  9. 回顾:你对Windows 8了解有多少?开启浏览器javascr
  10. .Net Compact Framework 高级篇(2)-- 扩展SOAP应用
  11. SpringBoot 使用小技巧合集
  12. Atitit. js mvc 总结(2)----angular 跟 Knockout o99 最佳实践
  13. Access数据库的查询
  14. 亳州学院计算机查询网址,亳州学院教务管理系统入口http://www.bzuu.edu.cn/jwc/
  15. Color Constancy Datasets
  16. 基于JAVA的校园论坛系统设计与实现
  17. logback prudent, SiftingAppender, layout, encoder的使用
  18. 在灰度图像上进行Mean Shift迭代搜索目标 ,一维加权直方图 + 巴氏系数 + Mean Shift迭代
  19. Sun公司,Oracle公司(10.8)
  20. mybatis实现数据库读写分离

热门文章

  1. 仅改变rowspan背景_山西耗资10亿的小镇,人称长治“小周庄”,距市中心仅16公里...
  2. Gradle本地化构建技巧之自定义Gradle配置文件
  3. 安全测试简述/安全审计工具
  4. web服务器也是端系统么,Web服务器和游戏服务器的那些事儿
  5. 大数据-NoSQL数据库:HBase【基于Zookeeper/HDFS的分布式、高并发、可扩展的NoSQL数据库;支持“十亿行”ד百万列”海量数据的实时随机读写;仅支持单表查询;不擅长数据分析】
  6. Handler源码分析 - Java层
  7. 14.[保护模式]TSS任务段
  8. 2010-2021年上市公司专利数据
  9. 由浅入深读透vue源码:diff算法
  10. P1247 取火柴游戏 (博弈论)