import sys
from sys import stdin
tt = int(stdin.readline())
ANS = []
for loop in range(tt):
n,m = map(int,stdin.readline().split())
lis = [ list(map(int,stdin.readline().split())) for i in range(n) ]
one = set()
for i in range(n):
one.add(lis[i][0])
A = None
for i in range(m):
a = list(map(int,stdin.readline().split()))
if a[0] in one:
A = a
rev = {}
a = A
for i in range(len(a)):
rev[a[i]] = i
nlis = []
for x in lis:
nlis.append( [rev[x[0]]] + x )
nlis.sort()
for i in nlis:
ANS.append(" ".join(map(str,i[1:])))
print ("\n".join(ANS))
Partitioning binary strings | Special sets |
Smallest chosen word | Going to office |
Color the boxes | Missing numbers |
Maximum sum | 13 Reasons Why |
Friend's Relationship | Health of a person |
Divisibility | A. Movement |
Numbers in a matrix | Sequences |
Split houses | Divisible |
Three primes | Coprimes |
Cost of balloons | One String No Trouble |
Help Jarvis! | Lift queries |
Goki and his breakup | Ali and Helping innocent people |
Book of Potion making | Duration |
Birthday Party | e-maze-in |
Bricks Game | Char Sum |