CF1413B A New Technique

题目描述

## 题意简述 有一张 $ n\times m $ 的表格,每一格写着不同的数字。但是表格被打乱了!现在给出从左到右每一行的元素,从上到下每一列的元素,但行和列的顺序是打乱的。请还原这张表。

输入格式

输入的第一行包括一个整数 $T$ $(1\le T \le100000)$表示测试用例的数量。 每个测试用例的第一行包含两个整数 $n,m$ $(1\le n,m \le500)$ 分别表示表格行数和列数。 下列 $n$ 行每行包含 $m$ 个整数,表示表中从左到右的任意行的元素。 下列 $m$ 行每行包含 $n$ 个整数,表示表中从上到下的任意列的元素。 保证每一行和每一列仅出现一次。

输出格式

对于每个测试用例,输出一个 $n\times m$ 的表格,表示还原后的表格。答案是唯一的。

说明/提示

Consider the first test case. The matrix is $ 2 \times 3 $ . You are given the rows and columns in arbitrary order. One of the rows is $ [6, 5, 4] $ . One of the rows is $ [1, 2, 3] $ . One of the columns is $ [1, 6] $ . One of the columns is $ [2, 5] $ . One of the columns is $ [3, 4] $ . You are to reconstruct the matrix. The answer is given in the output.