1005. Simple Sort

1005. Simple Sort


Description

Sorting is a basic function in any databases. Assume there are N entries in the given database. Every entry has M items. To determine the order, we are first required to provide the priorities among the columns. Priorities are measured by M distinctintegers. The lower integer indicates the higher priority.

To compare two entries, item in the column with highest priority is used. If equal, the items in the column with the second highest priority are compared. Then the 3rd to Nth highest column, until in which the items are not equal. If two entries are completely the same, the one given earlier in the data will rank first.

You are now given a job to implement the sorting function with different column priorities.

Input

The first integer T (≤30) indicates the number of cases. There follows T cases.

In every cases, the first line contain two integer N (≤100), M (≤10). N is the number of entries. M is the number of the column. The Nlines is followed, every line contains M integers. The jth integer in the ith line correspond with the content in the ith entry jth column. Then a number Q (≤10) follows indicating the number of the queries. In every line, there are M integers. The ith number is the priority of the ith column.

Output
For every case, output  Q lines. Every line contains  N distinct integers (numbered from 0 to  N-1) in ascending order with given priorities. Number  i means the ( i+1) th entry.
Sample Input
 Copy sample input to clipboard
1
6 3
1 1 1
1 2 3
2 2 4
2 2 3
3 1 2
3 2 2
4
1 2 3
0 1 2
30 20 10
0 -1 1
Sample Output
0 1 3 2 4 5
0 1 3 2 4 5
0 4 5 1 3 2
0 4 1 3 2 5

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值