编程介的小学生 2017-05-10 12:12 采纳率: 20.3%
浏览 751
已采纳

Save These Poor Trees

WishingTree, a kind old man, had a large piece of land on which he planted all kinds of trees, apple tree, peach tree, pine, etc. The trees are so well planted that they form a square of n rows and n colomns.

WishingTree, as his name indicated, loved his trees very much. He took good care of the trees and lead on a happy life. Howerever, disaster soon came. A monster called WantingTree wanted to eat his trees. The monster ate nothing but trees, every year, he would went out from his cave and spent k days to fill his stomach up, and then back to sleep again. WantingTree is not a fool, as he knew that mixing diffrent kinds of trees in his stomach may cause complex chemical reaction which might result in poisonous substances, he ate one kind of tree in a year. What's more, he was an efficient monster, each of the k day he chose a single row or column of tree, and ate all the wanted-trees in the row or column. LoveingTree could not fight against WisingTree, but he really thought he could do something. He decided to persuade WantingTree into eating a certain kind of tree, in hope that the number of kinds of his trees is not to decrease, anyway a tree will grow into a forest.

Your are to write a program to figure out which kind of tree can be choose to be eaten by WantingTree, put in another way, WantingTree can not eat all the trees of this kind in k days.

You will be provided these informations:

k: the number of days which WishingTress spent to fill up his stomach. (0 < k < N)

N: the number of rows and columns of the trees (1 < N <= 100)

A matrix of M x N, where Aij denote the tree name of the tree in the i row, j column.

tree name is a single upper case letters from 'A' to 'Z'

Input

First line is a single integer T, specify the number of test cases. each test case begins with a line containg two integer N, K in a single line, followed by N lines describing tree names, each line consists of N upper case letters. There are no space between these letters.

Output

For each test case, print in ascending order all the trees name of which can not be eaten up in k days by WantingTree in a single line. If there is no choice, print "Poor WishingTree!" instead. Print a blank line after each test case.

Sample Input

3

2 1
AA
AB
2 1
AB
BB
5 4
ABCDE
BCDEA
CDEAB
DEABC
EABCD

Sample Output

A

B

ABCDE

  • 写回答

1条回答 默认 最新

  • threenewbee 2017-05-28 15:38
    关注
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
  • ¥20 Java-Oj-桌布的计算
  • ¥15 powerbuilder中的datawindow数据整合到新的DataWindow
  • ¥20 有人知道这种图怎么画吗?
  • ¥15 pyqt6如何引用qrc文件加载里面的的资源
  • ¥15 安卓JNI项目使用lua上的问题
  • ¥20 RL+GNN解决人员排班问题时梯度消失
  • ¥60 要数控稳压电源测试数据
  • ¥15 能帮我写下这个编程吗
  • ¥15 ikuai客户端l2tp协议链接报终止15信号和无法将p.p.p6转换为我的l2tp线路