You finally woke up after this crazy dream and decided to walk around to clear your head. Outside you saw your house's fence — so plain and boring, that you'd like to repaint it.

You have a fence consisting of $n$ planks, where the $i$-th plank has the color $a_i$. You want to repaint the fence in such a way that the $i$-th plank has the color $b_i$.

You've invited $m$ painters for this purpose. The $j$-th painter will arrive at the moment $j$ and will recolor exactly one plank to color $c_j$. For each painter you can choose which plank to recolor, but you can't turn them down, i. e. each painter has to color exactly one plank.

Can you get the coloring $b$ you want? If it's possible, print for each painter which plank he must paint.


-----Input-----

The first line contains one integer $t$ ($1 \le t \le 10^4$) — the number of test cases. Then $t$ test cases follow.

The first line of each test case contains two integers $n$ and $m$ ($1 \le n, m \le 10^5$) — the number of planks in the fence and the number of painters.

The second line of each test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le n$) — the initial colors of the fence.

The third line of each test case contains $n$ integers $b_1, b_2, \dots, b_n$ ($1 \le b_i \le n$) — the desired colors of the fence.

The fourth line of each test case contains $m$ integers $c_1, c_2, \dots, c_m$ ($1 \le c_j \le n$) — the colors painters have.

It's guaranteed that the sum of $n$ doesn't exceed $10^5$ and the sum of $m$ doesn't exceed $10^5$ over all test cases.


-----Output-----

For each test case, output "NO" if it is impossible to achieve the coloring $b$.

Otherwise, print "YES" and $m$ integers $x_1, x_2, \dots, x_m$, where $x_j$ is the index of plank the $j$-th painter should paint.

You may print every letter in any case you want (so, for example, the strings "yEs", "yes", "Yes" and "YES" are all recognized as positive answer).


-----Examples-----

Input
6
1 1
1
1
1
5 2
1 2 2 1 1
1 2 2 1 1
1 2
3 3
2 2 2
2 2 2
2 3 2
10 5
7 3 2 1 7 9 4 2 7 9
9 9 2 1 4 9 4 2 3 9
9 9 7 4 3
5 2
1 2 2 1 1
1 2 2 1 1
3 3
6 4
3 4 2 4 1 2
2 3 1 3 1 1
2 2 3 4
Output
YES
1
YES
2 2
YES
1 1 1
YES
2 1 9 5 9
NO
NO


-----Note-----

None

Source: codeforces | Difficulty: MEDIUM_HARD
Tags: Greedy algorithms

Complete search

Constructive algorithms


Solutions:
import os
import sys
from collections import defaultdict
from io import BytesIO, IOBase
nmbr = lambda : int(input())
lst = lambda : list(map(int, input().split()))

def main():

	def check(ans):
		for i in range(k):
			a[ans[i] - 1] = c[i]
		for (v, v1) in zip(a, b):
			if v != v1:
				return False
		return True
	for _ in range(nmbr()):
		(n, k) = lst()
		a = lst()
		b = lst()
		ans = []
		c = lst()
		eq = {}
		mp = defaultdict(list)
		ln = {}
		for i in range(n):
			if a[i] == b[i]:
				eq[a[i]] = i
			else:
				mp[b[i]] += [i]
				ln[b[i]] = ln.get(b[i], 0) + 1
		for i in range(k):
			v = c[i]
			sz = ln.get(v, 0)
			if sz > 0:
				ans += [mp[v][sz - 1] + 1]
				eq[v] = mp[v][sz - 1]
				ln[v] -= 1
			elif v in eq:
				ans += [eq[v] + 1]
			else:
				ans += [-1]
		for i in range(k - 1, 0, -1):
			if ans[i - 1] == -1:
				ans[i - 1] = ans[i]
		if ans[-1] != -1 and check(ans):
			sys.stdout.write('YES\n')
			for v in ans:
				sys.stdout.write(str(v) + ' ')
		else:
			sys.stdout.write('NO')
		print()
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
for t in range(1):
	main()


def solve():
	d = dict()
	pd = dict()
	o = b.index(c[-1])
	for i in range(m):
		if c[i] in pd:
			pd[c[i]] += 1
		else:
			pd[c[i]] = 1
	for i in range(n):
		if a[i] != b[i]:
			if b[i] in d:
				d[b[i]].append(i)
			else:
				d[b[i]] = [i]
		else:
			b[i] = 0
	for (k, v) in d.items():
		if k in pd:
			if pd[k] < len(v):
				return ('NO', [])
		else:
			return ('NO', [])
	if c[-1] in b:
		o = b.index(c[-1])
	order = []
	for i in range(m):
		if c[i] in d:
			if len(d[c[i]]) != 0:
				order.append(d[c[i]][-1] + 1)
				d[c[i]].pop()
			else:
				order.append(o + 1)
		else:
			order.append(o + 1)
	return ('YES', order)
t = int(input())
for z in range(t):
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	c = list(map(int, input().split()))
	if c[-1] not in b:
		print('NO')
	else:
		(p, q) = solve()
		if p == 'NO':
			print('NO')
		else:
			print('YES')
			print(*q)


from sys import stdin
import sys
tt = int(stdin.readline())
for loop in range(tt):
	(n, m) = map(int, stdin.readline().split())
	a = list(map(int, stdin.readline().split()))
	b = list(map(int, stdin.readline().split()))
	c = list(map(int, stdin.readline().split()))
	dic = [[] for i in range(n + 1)]
	for i in range(n):
		if a[i] != b[i]:
			dic[b[i]].append(i)
	end = [None] * n
	ans = [0] * m
	if c[-1] not in b:
		print('NO')
		continue
	for i in range(m - 1, -1, -1):
		if i == m - 1:
			if len(dic[c[i]]) > 0:
				ableind = dic[c[i]][-1]
				ans[i] = dic[c[i]][-1]
				del dic[c[i]][-1]
			else:
				for j in range(n):
					if b[j] == c[i]:
						ableind = j
						ans[i] = j
		elif len(dic[c[i]]) > 0:
			ans[i] = dic[c[i]][-1]
			del dic[c[i]][-1]
		else:
			ans[i] = ableind
	fl = True
	for i in range(n + 1):
		if len(dic[i]) > 0:
			fl = False
	if fl:
		print('YES')
		for i in range(m):
			ans[i] += 1
		print(*ans)
	else:
		print('NO')


from __future__ import division, print_function
import sys
import os
from io import BytesIO, IOBase
from heapq import heappush, heappop
from math import gcd, factorial, floor, ceil, sqrt, log2
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))

def inp():
	return sys.stdin.readline().rstrip('\r\n')

def out(var):
	sys.stdout.write(str(var))

def lis():
	return list(map(int, inp().split()))

def stringlis():
	return list(map(str, inp().split()))

def sep():
	return map(int, inp().split())

def strsep():
	return map(str, inp().split())

def testcase(t):
	for pp in range(t):
		solve(pp)

def google(p):
	print('Case #' + str(p) + ': ', end='')

def lcm(a, b):
	return a * b // gcd(a, b)

def power(x, y, p):
	y %= p - 1
	res = 1
	x = x % p
	if x == 0:
		return 0
	while y > 0:
		if y & 1 == 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res

def ncr(n, r):
	return factorial(n) // (factorial(r) * factorial(max(n - r, 1)))

def isPrime(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	i = 5
	while i * i <= n:
		if n % i == 0 or n % (i + 2) == 0:
			return False
		i = i + 6
	return True
inf = pow(10, 20)
mod = 10 ** 9 + 7

def solve(case):
	(n, m) = sep()
	a = lis()
	b = lis()
	c = lis()
	if a == b:
		if c[-1] in b:
			print('YES')
			ans = [b.index(c[-1]) + 1] * m
			print(' '.join((str(i) for i in ans)))
		else:
			print('NO')
		return
	else:
		chng = {}
		for i in range(n):
			if a[i] == b[i]:
				continue
			if b[i] in chng:
				chng[b[i]] += 1
			else:
				chng[b[i]] = 1
		temp = chng.copy()
		for i in range(m):
			if c[i] in chng and chng[c[i]] > 0:
				chng[c[i]] -= 1
		for i in chng:
			if chng[i] > 0:
				print('NO')
				return
		diff = {}
		same = {}
		for i in range(n):
			if a[i] == b[i]:
				if b[i] not in same:
					same[b[i]] = [i]
				else:
					same[b[i]].append(i)
			elif b[i] not in diff:
				diff[b[i]] = [i]
			else:
				diff[b[i]].append(i)
		have = -1
		ans = [-1] * m
		for i in range(m - 1, -1, -1):
			if c[i] in diff and len(diff[c[i]]) > 0:
				ans[i] = diff[c[i]].pop()
				have = ans[i]
			elif have == -1:
				if c[i] in same:
					ans[i] = same[c[i]][0]
					have = ans[i]
				else:
					print('NO')
					return
			else:
				ans[i] = have
		print('YES')
		print(' '.join((str(i + 1) for i in ans)))
testcase(int(inp()))


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
for t in range(int(input())):
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	c = list(map(int, input().split()))
	l = []
	la = [0] * (n + 1)
	lb = [0] * (n + 1)
	lc = [0] * (n + 1)
	d = [[] for i in range(n + 1)]
	d1 = [[] for i in range(n + 1)]
	d2 = [[] for i in range(n + 1)]
	for i in range(n):
		if a[i] != b[i]:
			l.append(i)
			la[a[i]] += 1
			lb[b[i]] += 1
			d2[b[i]].append(i)
		else:
			d1[b[i]].append(i)
	for i in range(m):
		lc[c[i]] += 1
		d[c[i]].append(i)
	ans = 'YES'
	for i in l:
		if lc[b[i]] == 0:
			ans = 'NO'
			break
	if m < len(l):
		ans = 'NO'
	for i in l:
		if lb[b[i]] > lc[b[i]]:
			ans = 'NO'
			break
	if c[-1] not in b:
		ans = 'NO'
	if ans == 'YES':
		l1 = [-1] * m
		l2 = [0] * (n + 1)
		q = 0
		for i in range(m - 1, -1, -1):
			if len(d2[c[i]]):
				l1[i] = d2[c[i]].pop() + 1
				l2[l1[i]] = i
				if not q:
					q = l1[i]
			elif len(d1[c[i]]):
				l1[i] = d1[c[i]][-1] + 1
				l2[l1[i]] = i
				if not q:
					q = l1[i]
			elif q:
				l1[i] = q
			else:
				ans = 'NO'
				break
	print(ans)
	if ans == 'YES':
		print(*l1)


from sys import stdin, stdout
input = stdin.readline
for _ in range(int(input())):
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	c = list(map(int, input().split()))
	dic = {}
	for i in range(n):
		if a[i] != b[i]:
			if b[i] in dic:
				dic[b[i]].append(i)
			else:
				dic[b[i]] = [i]
	m_dic = {}
	for i in c:
		if i in m_dic:
			m_dic[i] += 1
		else:
			m_dic[i] = 1
	flag = 0
	for i in dic:
		if i not in m_dic:
			flag = 1
			print('NO')
			break
		if len(dic[i]) > m_dic[i]:
			flag = 1
			print('NO')
			break
	if flag == 1:
		continue
	if c[-1] not in b:
		print('NO')
		continue
	ans = []
	if c[-1] in dic:
		last_ind = dic[c[-1]][0]
	else:
		last_ind = b.index(c[-1])
	for i in range(m):
		if c[i] not in dic:
			ans.append(last_ind + 1)
		else:
			ans.append(dic[c[i]][-1] + 1)
			if len(dic[c[i]]) > 1:
				dic[c[i]].pop()
	print('YES')
	print(*ans)


from sys import stdin
input = lambda : stdin.readline().strip()
lin = lambda : list(map(int, input().split()))
iin = lambda : int(input())
main = lambda : map(int, input().split())
from math import ceil, sqrt, factorial, log
from collections import deque
from bisect import bisect_left

def gcd(a, b):
	(a, b) = (max(a, b), min(a, b))
	while a % b != 0:
		(a, b) = (b, a % b)
	return b
mod = 998244353

def solve(we):
	(n, m) = main()
	a = lin()
	b = lin()
	c = lin()
	d = {}
	not_change = {}
	for i in range(n):
		if a[i] != b[i]:
			if b[i] in d:
				d[b[i]].add(i)
			else:
				d[b[i]] = set()
				d[b[i]].add(i)
		else:
			not_change[b[i]] = i
	z = {}
	for i in range(m):
		if c[i] not in z:
			z[c[i]] = set()
		z[c[i]].add(i)
	flag = 1
	ans = [-1 for i in range(m)]
	for i in d:
		if i in z and len(z[i]) >= len(d[i]):
			x = list(d[i])
			y = list(z[i])
			if i not in not_change:
				not_change[i] = x[-1]
			j = 0
			for i in x:
				ans[y[j]] = i
				j += 1
				j = j % m
		else:
			flag = 0
			break
	if flag:
		x = -1
		for i in range(m - 1, -1, -1):
			if ans[i] >= 0:
				x = ans[i]
			elif x >= 0:
				ans[i] = x
			elif c[i] in not_change:
				ans[i] = not_change[c[i]]
				x = ans[i]
			ans[i] += 1
		if 0 in ans:
			print('NO')
		else:
			print('YES')
			print(*ans)
	else:
		print('NO')
qwe = 1
qwe = int(input())
for _ in range(qwe):
	solve(_ + 1)


from __future__ import division, print_function
import os
import sys
from collections import defaultdict
from io import BytesIO, IOBase
if sys.version_info[0] < 3:
	from __builtin__ import xrange as range
	from future_builtins import ascii, filter, hex, map, oct, zip

def main():
	t = int(input())
	for _ in range(t):
		(n, m) = map(int, input().split())
		a = [int(ai) for ai in input().split()]
		b = [int(bi) for bi in input().split()]
		c = [int(ci) for ci in input().split()]
		changes = defaultdict(list)
		for (i, (ai, bi)) in enumerate(zip(a, b)):
			if ai != bi:
				changes[bi].append(i)
		last = -1
		sol = [-1] * m
		for (i, ci) in enumerate(c):
			if changes[ci]:
				last = sol[i] = changes[ci].pop()
		if sol[-1] == -1 and c[-1] in b:
			last = sol[-1] = b.index(c[-1])
		poss = sol[-1] != -1 and all((idx == [] for (_, idx) in changes.items()))
		sol = [last if i == -1 else i for i in sol]
		if poss:
			print('YES')
			print(*[i + 1 for i in sol])
		else:
			print('NO')
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


import sys
import os
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
import copy
mod = 10 ** 9 + 7

def lcm(x, y):
	return x * y / gcd(x, y)

def fact(x, mod=mod):
	ans = 1
	for i in range(1, x + 1):
		ans = ans * i % mod
	return ans

def arr2D(n, m, default=0):
	return [[default for j in range(m)] for i in range(n)]

def arr3D(n, m, r, default=0):
	return [[[default for k in range(r)] for j in range(m)] for i in range(n)]

def sortDictV(x):
	return {k: v for (k, v) in sorted(x.items(), key=lambda item: item[1])}

class DSU:

	def __init__(self, length):
		self.length = length
		self.parent = [-1] * self.length

	def getParent(self, node, start):
		if node >= self.length:
			return False
		if self.parent[node] < 0:
			if start != node:
				self.parent[start] = node
			return node
		return self.getParent(self.parent[node], start)

	def union(self, node1, node2):
		parent1 = self.getParent(node1, node1)
		parent2 = self.getParent(node2, node2)
		if parent1 == parent2:
			return False
		elif self.parent[parent1] <= self.parent[parent2]:
			self.parent[parent1] += self.parent[parent2]
			self.parent[parent2] = parent1
		else:
			self.parent[parent2] += self.parent[parent1]
			self.parent[parent1] = parent2
		return True

	def getCount(self, node):
		return -self.parent[self.getParent(node, node)]

def exact(num):
	if abs(num - round(num)) <= 10 ** (-9):
		return round(num)
	return num

def notSame(a, b):
	for i in range(len(a)):
		if a[i] != b[i]:
			return True
	return False

def solve(n, m, a, b, c):
	diff = 0
	want = {}
	for i in range(n):
		if a[i] != b[i]:
			diff += 1
			if want.get(b[i]) == None:
				want[b[i]] = 1
			else:
				want[b[i]] += 1
	needed = 0
	cMap = {}
	for i in c:
		if cMap.get(i) == None:
			cMap[i] = 0
		cMap[i] += 1
	for i in cMap:
		val = want.get(i)
		if val == None:
			val = 0
		needed += min(val, cMap[i])
	if needed < diff:
		print('NO')
		return
	if c[-1] not in b:
		print('NO')
		return
	lastind = -1
	get = False
	for i in range(n):
		if a[i] != b[i] and b[i] == c[-1]:
			lastind = i
			get = True
	if get == False:
		for i in range(n):
			if b[i] == c[-1]:
				lastind = i
	paintedTo = {}
	for i in range(n):
		if a[i] != b[i] and i != lastind:
			if paintedTo.get(b[i]) == None:
				paintedTo[b[i]] = [i]
			else:
				paintedTo[b[i]].append(i)
	ans = []
	for i in c[:-1]:
		if paintedTo.get(i) == None:
			ans.append(lastind)
		elif len(paintedTo[i]) == 0:
			ans.append(lastind)
		else:
			val = paintedTo[i].pop()
			if val == lastind:
				val = paintedTo[i].pop()
			ans.append(val)
	print('YES')
	for i in ans:
		print(i + 1, end=' ')
	print(lastind + 1)
	return
for _ in range(int(input())):
	(n, m) = list(map(int, input().split()))
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	c = list(map(int, input().split()))
	solve(n, m, a, b, c)


from collections import defaultdict, Counter
t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	a = [int(x) for x in input().split()]
	b = [int(x) for x in input().split()]
	c = [int(x) for x in input().split()]
	colorToIndex = defaultdict(list)
	for i in range(n):
		if a[i] != b[i]:
			colorToIndex[b[i]].append(i)
	result = [-1 for _ in range(m)]
	possible = True
	if colorToIndex[c[-1]]:
		result[-1] = colorToIndex[c[-1]].pop()
		a[result[-1]] = c[-1]
	else:
		for i in range(n):
			if a[i] == b[i] and b[i] == c[-1]:
				result[-1] = i
				break
		else:
			possible = False
	if not possible:
		print('NO')
	else:
		for i in range(m - 1):
			if colorToIndex[c[i]]:
				result[i] = colorToIndex[c[i]].pop()
				a[result[i]] = c[i]
			else:
				result[i] = result[-1]
		if all((a[i] == b[i] for i in range(n))):
			print('YES')
			result = [x + 1 for x in result]
			print(*result)
		else:
			print('NO')


import sys, os.path
from collections import defaultdict
if os.path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
for _ in range(int(input())):
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	c = list(map(int, input().split()))
	flag = True
	l = [[] for i in range(n + 1)]
	ind = 0
	for i in range(n):
		if b[i] == c[-1]:
			flag = False
			ind = i
			if b[i] != a[i]:
				ind = i
				break
	if flag:
		print('NO')
	else:
		for i in range(n):
			if a[i] != b[i]:
				l[b[i]].append(i)
		flag = True
		ans = []
		for i in range(m):
			if len(l[c[i]]) == 0:
				ans.append(ind + 1)
				a[ind] = c[i]
			else:
				ans.append(l[c[i]][-1] + 1)
				a[l[c[i]][-1]] = c[i]
				l[c[i]].pop()
		for i in range(n):
			if a[i] != b[i]:
				flag = False
				break
		if flag:
			print('YES')
			print(*ans)
		else:
			print('NO')


t = int(input())
for _ in range(t):
	(a, b) = map(int, input().split())
	f = list(map(int, input().split()))
	s = list(map(int, input().split()))
	an = list(map(int, input().split()))
	l = [[] for i in range(a + 1)]
	sa = 0
	bsa = 0
	amo = 0
	for i in range(a):
		if s[i] == an[-1] and (sa == 0 or f[i] != s[i]):
			sa = i + 1
		if f[i] != s[i]:
			l[s[i]].append(i)
			amo += 1
	if sa == 0:
		print('NO')
		continue
	ans = []
	for i in range(1, b + 1):
		if len(l[an[-i]]) > 0:
			ans.append(l[an[-i]][-1] + 1)
			l[an[-i]].pop()
			amo -= 1
		else:
			ans.append(sa)
	if amo != 0:
		print('NO')
	else:
		ans.reverse()
		print('YES')
		for i in ans:
			print(i, end=' ')
		print()


from collections import defaultdict
T = int(input())

def array(f):
	return list(map(f, input().split()))

def solver():
	(n, m) = map(int, input().split())
	bef = array(int)
	aft = array(int)
	painter = array(int)
	painter_color = defaultdict(list)
	painter_left = [0] * (n + 1)
	for (i, c) in enumerate(painter):
		painter_left[c] += 1
	for i in range(n):
		if bef[i] != aft[i]:
			if painter_left[aft[i]] == 0:
				print('NO')
				return
			painter_left[aft[i]] -= 1
			painter_color[aft[i]].append(i)
	if all((painter[-1] != elem for elem in aft)):
		print('NO')
		return
	print('YES')
	const_idx = -1
	res_array = []
	for i in range(1, m + 1):
		color = painter[-i]
		if i == 1:
			for j in range(n):
				if bef[j] != aft[j] and aft[j] == color:
					const_idx = j
					break
			if const_idx < 0:
				for j in range(n):
					if bef[j] == aft[j] and aft[j] == color:
						const_idx = j
						break
			assert const_idx >= 0
			res_array.append(const_idx + 1)
			if const_idx in painter_color[color]:
				painter_color[color].remove(const_idx)
			continue
		if painter_color[color]:
			v = painter_color[color].pop()
			res_array.append(v + 1)
			continue
		else:
			res_array.append(const_idx + 1)
	print(*res_array[::-1])
	return
for _ in range(T):
	solver()


from collections import defaultdict

def main():
	for _ in range(int(input())):
		(n, m) = list(map(int, input().split()))
		a = list(map(int, input().split()))
		b = list(map(int, input().split()))
		c = list(map(int, input().split()))
		ind = defaultdict(list)
		fre = defaultdict(int)
		for i in range(m):
			ind[c[i]].append(i)
			fre[c[i]] += 1
		ll = [0] * m
		for i in range(n):
			if a[i] != b[i]:
				if fre[b[i]] > 0:
					fre[b[i]] -= 1
					ll[ind[b[i]].pop()] = i + 1
				else:
					print('NO')
					break
		else:
			majaor = 0
			if ll.count(0) == m:
				k = c[-1]
				if k in b:
					ll[-1] = len(b) - 1 - b[::-1].index(k)
					val = ll[-1] + 1
					for ii in range(m):
						ll[ii] = val
				else:
					majaor = 1
			else:
				val = 0
				for ii in range(m - 1, -1, -1):
					if ll[ii] != 0:
						val = ll[ii]
					elif ll[ii] == 0 and val == 0:
						if c[ii] in b:
							ll[ii] = b.index(c[ii]) + 1
							val = ll[ii]
						else:
							majaor = 1
					elif ll[ii] == 0 and val != 0:
						ll[ii] = val
			if majaor == 0:
				print('YES')
				print(*ll)
			else:
				print('NO')

def random():
	rating = 100
	rating = rating * 100
	rating = rating * 100
	print(rating)

def random():
	rating = 100
	rating = rating * 100
	rating = rating * 100
	print(rating)
import os, sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()

def random():
	rating = 100
	rating = rating * 100
	rating = rating * 100
	print(rating)

def random():
	rating = 100
	rating = rating * 100
	rating = rating * 100
	print(rating)

def random():
	rating = 100
	rating = rating * 100
	rating = rating * 100
	print(rating)

def random():
	rating = 100
	rating = rating * 100
	rating = rating * 100
	print(rating)


import sys, getpass
import math, random
import functools, itertools, collections, heapq, bisect
from collections import Counter, defaultdict, deque
input = sys.stdin.readline
M9 = 10 ** 9 + 7
MAXINT = sys.maxsize
OFFLINE_TEST = getpass.getuser() == 'hkmac'

def log(*args):
	if OFFLINE_TEST:
		print('\x1b[36m', *args, '\x1b[0m', file=sys.stderr)

def solve(*args):
	if OFFLINE_TEST:
		log('----- solving ------')
		log(*args)
		log('----- ------- ------')
	return solve_(*args)

def read_matrix(rows):
	return [list(map(int, input().split())) for _ in range(rows)]

def read_strings(rows):
	return [input().strip() for _ in range(rows)]

def solve_(arr, brr, crr):
	if crr[-1] not in brr:
		log('last painter not in result')
		return []
	c_able = Counter(arr) + Counter(crr)
	c_required = Counter(brr)
	for (color, required) in c_required.items():
		if c_able[color] < required:
			log(color)
			log('not enough painters')
			return []
	required = defaultdict(list)
	for (i, (a, b)) in enumerate(zip(arr, brr)):
		if a != b:
			required[b].append(i)
	last_color = crr[-1]
	if required[last_color]:
		last_fence = required[last_color].pop()
	else:
		last_fence = brr.index(last_color)
	res = [last_fence]
	for c in crr[:-1][::-1]:
		if required[c]:
			res.append(required[c].pop())
		else:
			res.append(last_fence)
	res = res[::-1]
	for (c, r) in zip(crr, res):
		arr[r] = c
	log(arr)
	if not arr == brr:
		log('error 1')
		return []
	for v in required.values():
		if v:
			log('error 2')
			return []
	return res
for case_num in range(int(input())):
	(n, m) = list(map(int, input().split()))
	arr = list(map(int, input().split()))
	brr = list(map(int, input().split()))
	crr = list(map(int, input().split()))
	res = solve(arr, brr, crr)
	res = [1 + x for x in res]
	if res:
		print('YES')
		print(*res)
	else:
		print('NO')


def find():
	(n, m) = map(int, input().split())
	old = list(map(int, input().split()))
	new = list(map(int, input().split()))
	worker = list(map(int, input().split()))
	task = [[] for _ in range(n + 1)]
	for i in range(len(old)):
		if old[i] != new[i]:
			task[new[i]].append(i)
	last = -1
	if len(task[worker[-1]]) > 0:
		last = task[worker[-1]].pop()
	else:
		for i in range(len(new)):
			if new[i] == worker[-1]:
				last = i
				break
	if last == -1:
		return 'No'
	ans = [0] * m
	ans[-1] = last
	for i in range(len(worker) - 1):
		if len(task[worker[i]]) > 0:
			ans[i] = task[worker[i]].pop()
		else:
			ans[i] = last
	for i in task:
		if i:
			return 'No'
	return 'Yes\n' + ' '.join([str(i + 1) for i in ans])
for i in range(int(input())):
	print(find())


from sys import stdin
input = stdin.readline
t = int(input())
for _ in range(t):
	(n, m) = [int(x) for x in input().split()]
	a = [int(x) for x in input().split()]
	b = [int(x) for x in input().split()]
	c = [int(x) for x in input().split()]
	x = c[-1]
	g = -1
	d = {}
	for i in range(n):
		if b[i] == x:
			g = i
		if a[i] != b[i]:
			if b[i] in d:
				d[b[i]].append(i)
			else:
				d[b[i]] = [i]
	if g == -1:
		print('NO')
		continue
	if x in d:
		g = d[x].pop()
		if d[x] == []:
			del d[x]
	ans = []
	for i in range(m - 1):
		if c[i] in d:
			ans.append(d[c[i]].pop() + 1)
			if d[c[i]] == []:
				del d[c[i]]
		else:
			ans.append(g + 1)
	ans.append(g + 1)
	if d == {}:
		print('YES')
		print(*ans)
	else:
		print('NO')


import math
import bisect
import copy
from collections import defaultdict
from collections import OrderedDict
for _ in range(int(input())):
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	c = list(map(int, input().split()))
	ids = [[] for i in range(n + 1)]
	tot_req = [0] * (n + 1)
	req = [0] * (n + 1)
	last = [0] * (n + 1)
	ans = 0
	for i in range(n):
		if b[i] != a[i]:
			req[b[i]] += 1
			ids[b[i]].append(i)
		tot_req[b[i]] += 1
		last[b[i]] = i
	avail = [0] * (n + 1)
	for i in range(m):
		avail[c[i]] += 1
	for i in range(1, n + 1):
		if avail[i] < req[i]:
			print('no')
			ans = -1
			break
	if ans == 0:
		if tot_req[c[m - 1]] == 0:
			print('no')
		else:
			print('yes')
			if len(ids[c[m - 1]]) == 0:
				p = last[c[m - 1]]
			else:
				p = ids[c[m - 1]][0]
			for i in range(m):
				x = c[i]
				if len(ids[x]) == 0:
					print(p + 1, end=' ')
				else:
					print(ids[x][-1] + 1, end=' ')
					ids[x].pop()
			print()


from sys import stdin, gettrace
if gettrace():

	def inputi():
		return input()
else:

	def input():
		return next(stdin)[:-1]

	def inputi():
		return stdin.buffer.readline()

def solve():
	(n, m) = map(int, input().split())
	aa = [int(a) for a in input().split()]
	bb = [int(a) for a in input().split()]
	cc = [int(a) for a in input().split()]
	if cc[-1] not in bb:
		print('NO')
		return
	rcm = {}
	nrcm = {}
	for (i, (a, b)) in enumerate(zip(aa, bb)):
		if b != a:
			rcm[b] = rcm.get(b, []) + [i]
		else:
			nrcm[b] = i
	res = []
	for c in cc[::-1]:
		if c in rcm and rcm[c] != []:
			x = rcm[c].pop() + 1
		elif c in nrcm:
			x = nrcm[c] + 1
		else:
			x = res[0]
		res.append(x)
	if any((rcm[c] != [] for c in rcm)):
		print('NO')
		return
	print('YES')
	print(' '.join(map(str, res[::-1])))

def main():
	t = int(input())
	for _ in range(t):
		solve()
main()


from sys import stdin
t = int(stdin.readline())
for _ in range(t):
	flag = True
	(n, m) = map(int, stdin.readline().split())
	prev = list(map(int, stdin.readline().split()))
	aft = list(map(int, stdin.readline().split()))
	paints = list(map(int, stdin.readline().split()))
	diff = []
	for i in range(n):
		if prev[i] != aft[i]:
			diff.append(aft[i])
	dic_diff = {}
	for num in diff:
		if num not in dic_diff:
			dic_diff[num] = 1
		else:
			dic_diff[num] += 1
	dic_paints = {}
	for num in paints:
		if num not in dic_paints:
			dic_paints[num] = 1
		else:
			dic_paints[num] += 1
	for key in dic_diff:
		if key not in dic_paints or dic_paints[key] < dic_diff[key]:
			print('NO')
			flag = False
			break
	if not flag:
		continue
	elif paints[-1] not in aft:
		print('NO')
	else:
		trash = aft.index(paints[-1])
		positions = {}
		for i in range(n):
			if aft[i] == prev[i]:
				continue
			if aft[i] not in positions:
				positions[aft[i]] = [i]
			else:
				positions[aft[i]].append(i)
		if paints[-1] in positions:
			trash = positions[paints[-1]][0]
		ans = []
		for color in paints:
			if color in dic_diff and positions[color]:
				ans.append(1 + positions[color][-1])
				positions[color].pop(-1)
			else:
				ans.append(1 + trash)
		print('YES')
		print(' '.join(map(str, ans)))


import sys
input = lambda : sys.stdin.buffer.readline()
for _ in range(int(input())):
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	c = list(map(int, input().split()))
	last = c[-1]
	if last in b:
		idx = -1
		for i in range(n):
			if b[i] == last:
				idx = i
				break
		ch = [[] for i in range(n + 1)]
		ans = [-1 for i in range(m)]
		for i in range(n):
			if a[i] != b[i]:
				ch[b[i]].append(i + 1)
		if ch[last]:
			ans[-1] = ch[last].pop()
			idx = ans[-1] - 1
		else:
			ans[-1] = idx + 1
		for i in range(m - 1):
			if ch[c[i]]:
				ans[i] = ch[c[i]].pop()
			else:
				ans[i] = idx + 1
		if all((not ch[i] for i in range(n + 1))):
			print('YES')
			print(*ans)
		else:
			print('NO')
	else:
		print('NO')


from collections import deque, defaultdict
from math import sqrt, ceil, factorial, floor, inf, log2
import bisect
import sys
import copy

def get_array():
	return list(map(int, sys.stdin.readline().strip().split()))

def get_ints():
	return map(int, sys.stdin.readline().strip().split())

def input():
	return sys.stdin.readline().strip()
from math import gcd
for _ in range(int(input())):
	(n, m) = get_ints()
	a = get_array()
	b = get_array()
	c = get_array()
	d = defaultdict(list)
	d1 = defaultdict(int)
	d2 = dict()
	d3 = defaultdict(int)
	for i in range(n):
		if a[i] != b[i]:
			d[b[i]].append(i)
			d3[b[i]] += 1
		d2[b[i]] = i
	arr = [-1] * len(c)
	for i in range(len(c)):
		if d1[c[i]] < len(d[c[i]]):
			arr[i] = d[c[i]][d1[c[i]]]
			d1[c[i]] += 1
			d3[c[i]] -= 1
		elif c[i] in d2:
			arr[i] = d2[c[i]]
	arr1 = [-1] * len(c)
	prev = arr[len(c) - 1]
	for i in range(len(c) - 1, -1, -1):
		if arr[i] == -1:
			arr1[i] = prev
		else:
			arr1[i] = arr[i]
		prev = arr1[i]
	flag = 0
	for i in range(len(arr1)):
		if arr1[i] == -1:
			flag = 1
			break
		else:
			arr1[i] += 1
	for x in d3.values():
		if x != 0:
			flag = 1
			break
	if flag == 1:
		print('NO')
	else:
		print('YES')
		print(*arr1)


def solve():
	(n, m) = list(map(int, input().split()))
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	c = list(map(int, input().split()))
	req = [0 for i in range(n + 1)]
	maxreq = [0 for i in range(n + 1)]
	available = [0 for i in range(n + 1)]
	last = [0 for i in range(n + 1)]
	indexes = [[] for i in range(n + 1)]
	ans = [0 for i in range(m)]
	for i in range(n):
		if a[i] != b[i]:
			req[b[i]] += 1
			indexes[b[i]].append(i + 1)
		last[b[i]] = i + 1
		maxreq[b[i]] += 1
	for color in c:
		available[color] += 1
	for i in range(n + 1):
		if req[i] > available[i]:
			print('NO')
			return
	if maxreq[c[m - 1]] == 0:
		print('NO')
		return
	print('YES')
	wrong = None
	if indexes[c[m - 1]]:
		wrong = indexes[c[m - 1]][0]
	else:
		wrong = last[c[m - 1]]
	for i in range(m):
		if indexes[c[i]]:
			ans[i] = indexes[c[i]].pop()
		else:
			ans[i] = wrong
	print(*ans)
t = int(input())
while t:
	solve()
	t -= 1


from collections import defaultdict, deque
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def func(n, m, a, b, c):
	to_color = defaultdict(deque)
	answer = [0] * m
	last = -1
	x = c[-1]
	for i in range(n):
		if b[i] != x:
			continue
		if a[i] != b[i]:
			last = i
		elif last == -1 and a[i] == b[i]:
			last = i
	if last == -1:
		return 'NO'
	for i in range(n):
		if a[i] != b[i] and i != last:
			to_color[b[i]].append(i)
	for j in range(m - 1):
		if len(to_color[c[j]]) == 0:
			answer[j] = last + 1
			a[last] = c[j]
		else:
			x = to_color[c[j]].pop()
			a[x] = c[j]
			answer[j] = x + 1
	answer[-1] = last + 1
	a[last] = c[-1]
	for i in range(n):
		if a[i] != b[i]:
			return 'NO'
	return 'YES\n{}'.format(' '.join(map(str, answer)))
for _ in range(int(input())):
	(n1, m1) = map(int, input().split())
	a1 = list(map(int, input().split()))
	b1 = list(map(int, input().split()))
	c1 = list(map(int, input().split()))
	print(func(n1, m1, a1, b1, c1))


import os
import sys
from io import BytesIO, IOBase

def solve():
	(n, m) = list(map(int, input().split()))
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	c = list(map(int, input().split()))
	res = []
	lol = -1
	e = [[] for _ in range(n)]
	if c[-1] not in b:
		print('NO')
		return
	else:
		lol = b.index(c[-1])
		for i in range(len(b)):
			if b[i] == a[i]:
				b[i] = -1
				a[i] = -1
			else:
				e[b[i] - 1].append(i)
		if c[-1] in b:
			lol = b.index(c[-1])
		a[lol] = -1
		b[lol] = -1
		c.pop()
	for i in range(len(c)):
		if len(e[c[i] - 1]) == 0:
			res.append(lol + 1)
		else:
			x = e[c[i] - 1].pop()
			res.append(x + 1)
			a[x] = -1
			b[x] = -1
	res.append(lol + 1)
	if a != b:
		print('NO')
		return
	else:
		print('YES')
		for i in res:
			print(i, end=' ')
		print()
		return
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def main():
	t = int(input())
	while t:
		t -= 1
		solve()
main()


from os import path
import sys, time
from math import ceil, floor, gcd, log, log2, factorial
from collections import defaultdict, Counter, OrderedDict, deque
from functools import reduce
from operator import mul
maxx = float('inf')
I = lambda : int(sys.stdin.buffer.readline())
tup = lambda : map(int, sys.stdin.buffer.readline().split())
lint = lambda : [int(x) for x in sys.stdin.buffer.readline().split()]
S = lambda : sys.stdin.readline().strip('\n')
grid = lambda r: [lint() for i in range(r)]
stpr = lambda x: sys.stdout.write(f'{x}' + '\n')
star = lambda x: print(' '.join(map(str, x)))
localsys = 0
start_time = time.time()
if path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
for _ in range(I()):
	(n, m) = tup()
	(a, b, c) = (lint(), lint(), lint()[::-1])
	d = defaultdict(list)
	for i in range(n):
		if a[i] != b[i]:
			d[b[i]].append(i)
	if c[0] not in b:
		print('NO')
		continue
	(z, ans) = (d[c[0]][-1] if d[c[0]] else b.index(c[0]), [])
	for i in c:
		if not d[i]:
			ans.append(z + 1)
		else:
			ans.append(d[i].pop() + 1)
	for i in d:
		if len(d[i]):
			print('NO')
			break
	else:
		print('YES')
		print(*ans[::-1])
if localsys:
	print('\n\nTime Elased :', time.time() - start_time, 'seconds')


from collections import Counter
test = int(input())
while test:
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	c = list(map(int, input().split()))
	omap = {}
	posi = {}
	posb = {}
	omap2 = Counter(b)
	tr = True
	omap3 = Counter(c)
	for i in range(n):
		if a[i] != b[i]:
			if b[i] in omap:
				omap[b[i]] += 1
			else:
				omap[b[i]] = 1
			if b[i] in posi:
				posi[b[i]].append(i)
			else:
				posi[b[i]] = [i]
		if b[i] in posb:
			posb[b[i]].append(i)
		else:
			posb[b[i]] = [i]
	for (k, v) in omap.items():
		if k in omap3:
			if omap[k] > omap3[k]:
				tr = False
				break
		else:
			tr = False
			break
	if tr:
		li = []
		tr1 = True
		for i in range(m):
			if c[i] in posi:
				li.append(posi[c[i]].pop(0))
				if len(posi[c[i]]) == 0:
					del posi[c[i]]
			elif c[i] in posb:
				li.append(posb[c[i]][0])
			elif len(posi) > 0:
				for (k, v) in posi.items():
					li.append(v[0])
					break
			elif i != m - 1:
				if c[m - 1] in posb:
					li.append(posb[c[m - 1]][0])
			else:
				tr1 = False
				break
		if tr1:
			print('Yes')
			for i in li:
				print(i + 1, end=' ')
			print()
		else:
			print('No')
	else:
		print('No')
	test -= 1


def solve(n, m, a, b, c):
	weNeedDict = {}
	for i in range(n):
		if a[i] != b[i]:
			if b[i] not in weNeedDict:
				weNeedDict[b[i]] = [i]
			else:
				weNeedDict[b[i]].append(i)
	avail = {}
	for i in c:
		if i not in avail:
			avail[i] = 1
		else:
			avail[i] += 1
	for i in weNeedDict:
		if i not in avail:
			return False
		if avail[i] < len(weNeedDict[i]):
			return False
	if c[m - 1] not in set(b):
		return False
	if c[m - 1] not in weNeedDict:
		lastPos = b.index(c[m - 1]) + 1
	else:
		lastPos = weNeedDict[c[m - 1]][0] + 1
	answer = []
	for i in c:
		if i in weNeedDict:
			pos = weNeedDict[i].pop()
			answer.append(pos + 1)
			if not weNeedDict[i]:
				weNeedDict.__delitem__(i)
		else:
			answer.append(lastPos)
	return answer
for _ in range(int(input())):
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	c = list(map(int, input().split()))
	answer = solve(n, m, a, b, c)
	if answer:
		print('YES')
		for i in answer:
			print(i, end=' ')
		print()
	else:
		print('NO')


def some_random_function():
	x = 10
	x *= 100
	i_dont_know = x
	why_am_i_writing_this = x * x
	print(i_dont_know)
	print(why_am_i_writing_this)

def some_random_function5():
	x = 10
	x *= 100
	i_dont_know = x
	why_am_i_writing_this = x * x
	print(i_dont_know)
	print(why_am_i_writing_this)
import os, sys
from io import BytesIO, IOBase

def solve(n, m, a, b, c):
	if c[-1] not in b:
		print('NO')
		return
	req = b.index(c[-1])
	for i in range(n):
		if a[i] != b[i] and b[i] == c[-1]:
			req = i
			break
	dema = [[] for _ in range(n + 1)]
	for i in range(n):
		if i == req:
			continue
		if a[i] != b[i]:
			dema[b[i]].append(i + 1)
	ans = []
	for i in range(m - 1):
		if len(dema[c[i]]):
			ans.append(dema[c[i]].pop())
			a[ans[-1] - 1] = c[i]
		else:
			ans.append(req + 1)
			a[req] = c[i]
	a[req] = c[-1]
	ans.append(req + 1)
	if a == b:
		print('YES')
		print(*ans)
	else:
		print('NO')

def main():
	for _ in range(int(input())):
		(n, m) = map(int, input().split())
		a = list(map(int, input().split()))
		b = list(map(int, input().split()))
		c = list(map(int, input().split()))
		solve(n, m, a, b, c)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def some_random_function1():
	x = 10
	x *= 100
	i_dont_know = x
	why_am_i_writing_this = x * x
	print(i_dont_know)
	print(why_am_i_writing_this)

def some_random_function2():
	x = 10
	x *= 100
	i_dont_know = x
	why_am_i_writing_this = x * x
	print(i_dont_know)
	print(why_am_i_writing_this)

def some_random_function3():
	x = 10
	x *= 100
	i_dont_know = x
	why_am_i_writing_this = x * x
	print(i_dont_know)
	print(why_am_i_writing_this)

def some_random_function4():
	x = 10
	x *= 100
	i_dont_know = x
	why_am_i_writing_this = x * x
	print(i_dont_know)
	print(why_am_i_writing_this)

def some_random_function6():
	x = 10
	x *= 100
	i_dont_know = x
	why_am_i_writing_this = x * x
	print(i_dont_know)
	print(why_am_i_writing_this)

def some_random_function7():
	x = 10
	x *= 100
	i_dont_know = x
	why_am_i_writing_this = x * x
	print(i_dont_know)
	print(why_am_i_writing_this)

def some_random_function8():
	x = 10
	x *= 100
	i_dont_know = x
	why_am_i_writing_this = x * x
	print(i_dont_know)
	print(why_am_i_writing_this)
main()


import sys, os, io
input = sys.stdin.readline
from collections import defaultdict
T = int(input())
for t in range(T):
	check = 'YES'
	ans = []
	(N, M) = map(int, input().split())
	A = list(map(int, input().split()))
	B = list(map(int, input().split()))
	C = list(map(int, input().split()))
	lis1 = [[] for _ in range(N + 1)]
	lis2 = [0] * (N + 1)
	for i in range(N):
		if A[i] != B[i]:
			lis1[B[i]].append(i + 1)
		else:
			lis2[B[i]] = i + 1
	update_id = 0
	for i in range(M - 1, -1, -1):
		if len(lis1[C[i]]):
			update_id = lis1[C[i]].pop()
			ans.append(update_id)
		elif lis2[C[i]] > 0:
			ans.append(lis2[C[i]])
			update_id = lis2[C[i]]
		elif update_id > 0:
			ans.append(update_id)
		else:
			check = 'NO'
	for i in range(1, N + 1):
		if len(lis1[i]):
			check = 'NO'
	print(check)
	if check == 'YES':
		print(*ans[::-1])


from collections import defaultdict as dd
for _ in range(int(input())):
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	c = list(map(int, input().split()))
	dic = dd(lambda : 0)
	dic3 = dd(lambda : 0)
	dic2 = dd(lambda : [])
	for el in c:
		dic3[el] += 1
	i = 1
	req = 0
	ansTruth = True
	for (el, el1) in zip(b, a):
		if el != el1:
			req += 1
			if dic3[el] == 0:
				ansTruth = False
				break
			dic[el] += 1
			dic2[el].append(i)
		i += 1
	if not ansTruth:
		print('NO')
		continue
	ans = []
	chng = -1
	for el in c[::-1]:
		if dic[el] > 0:
			ind = dic2[el][dic[el] * -1]
			ans.append(ind)
			if a[ind - 1] != b[ind - 1]:
				req -= 1
			a[ind - 1] = el
			dic[el] -= 1
			if chng == -1:
				chng = ind
		elif chng != -1:
			ans.append(chng)
		elif el in b:
			chng = b.index(el) + 1
			ans.append(chng)
		else:
			ansTruth = False
			break
	if req > 0:
		ansTruth = False
	if ansTruth:
		print('YES')
		print(*ans[::-1])
	else:
		print('NO')


def Sort(sub_li):
	return sorted(sub_li, key=lambda x: x[1])
import math
n = int(input())
for i in range(0, n):
	o = input().rstrip().split(' ')
	p = input().rstrip().split(' ')
	q = input().rstrip().split(' ')
	r = input().rstrip().split(' ')
	L = []
	Q = []
	W = []
	S = []
	D = []
	for j in range(0, len(p)):
		D = []
		if int(p[j]) != int(q[j]):
			D.append(int(p[j]))
			D.append(int(q[j]))
			D.append(j)
			L.append(D)
		else:
			D.append(int(p[j]))
			D.append(int(q[j]))
			D.append(j)
			Q.append(D)
	L = Sort(L)
	Q = Sort(Q)
	E = []
	ans = [-1] * int(o[1])
	last = -1
	for j in range(len(r) - 1, -1, -1):
		A = int(r[j])
		I = 0
		J = len(L) - 1
		V = -1
		while I <= J:
			m = (I + J) // 2
			if L[m][1] == A:
				V = m
				if last == -1:
					last = j
				ans[j] = L[m][2]
				del L[m]
				E.append(j)
				break
			elif L[m][1] > A:
				J = m - 1
			else:
				I = m + 1
	if len(L) != 0:
		print('NO')
	else:
		no = 0
		for j in range(0, len(r)):
			if ans[j] == -1:
				A = int(r[j])
				if j <= last:
					ans[j] = ans[last]
		for j in range(len(r) - 1, -1, -1):
			if ans[j] == -1:
				A = int(r[j])
				if 1:
					I = 0
					J = len(Q) - 1
					V = -1
					while I <= J:
						m = (I + J) // 2
						if Q[m][1] == A:
							V = m
							ans[j] = Q[m][2]
							last = Q[m][2]
							break
						elif Q[m][1] > A:
							J = m - 1
						else:
							I = m + 1
					if V == -1:
						no = 1
						break
					else:
						break
		if no == 1:
			print('NO')
		else:
			print('YES')
			for j in range(0, len(ans)):
				if ans[j] == -1:
					print(last + 1, end=' ')
				else:
					print(ans[j] + 1, end=' ')
			print()


import sys
import math

def II():
	return int(sys.stdin.readline())

def LI():
	return list(map(int, sys.stdin.readline().split()))

def MI():
	return map(int, sys.stdin.readline().split())

def SI():
	return sys.stdin.readline().strip()

def FACT(n, mod):
	s = 1
	facts = [1]
	for i in range(1, n + 1):
		s *= i
		s %= mod
		facts.append(s)
	return facts[n]

def C(n, k, mod):
	return FACT(n, mod) * pow(FACT(k, mod) * FACT(n - k, mod) % mod, mod - 2, mod) % mod
t = II()
for q in range(t):
	(n, m) = MI()
	a = LI()
	b = LI()
	c = LI()
	x = [-1 for i in range(m)]
	d = {}
	for i in range(n):
		if a[i] != b[i]:
			if d.get(b[i]):
				d[b[i]].append(i + 1)
			else:
				d[b[i]] = [i + 1]
	d1 = {}
	d2 = {}
	for i in range(n):
		if not d2.get(b[i]):
			d2[b[i]] = i + 1
	for i in range(m):
		if d1.get(c[i]):
			d1[c[i]] += 1
		else:
			d1[c[i]] = 1
	boo = True
	for i in d:
		if not d1.get(i) or len(d[i]) > d1[i]:
			boo = False
			break
	if boo:
		for i in range(m):
			if d.get(c[i]):
				x[i] = d[c[i]].pop()
			elif d2.get(c[i]):
				x[i] = d2[c[i]]
	if boo:
		last = -1
		for i in range(m - 1, -1, -1):
			if x[i] == -1:
				if last == -1:
					boo = False
					break
				x[i] = last
			else:
				last = x[i]
	if boo:
		print('YES')
		print(*x)
	else:
		print('NO')


import sys
input = sys.stdin.readline

def inp():
	return int(input())

def st():
	return input().rstrip('\n')

def lis():
	return list(map(int, input().split()))

def maa():
	return map(int, input().split())
t = inp()
while t:
	t -= 1
	(n, m) = maa()
	a = lis()
	b = lis()
	c = lis()
	ma = {}
	uma = {}
	for i in range(n):
		if a[i] == b[i]:
			try:
				ma[a[i]].append(i)
			except:
				ma[a[i]] = [i]
		else:
			try:
				uma[b[i]].append(i)
			except:
				uma[b[i]] = [i]
	fl = 0
	mo = []
	rush = 0
	for i in range(m):
		if c[i] in uma:
			for k in range(rush + 1):
				mo.append(uma[c[i]][-1] + 1)
			rush = 0
			fuk = uma[c[i]].pop()
			try:
				ma[c[i]].append(fuk)
			except:
				ma[c[i]] = [fuk]
			if len(uma[c[i]]) == 0:
				del uma[c[i]]
			continue
		elif c[i] not in ma:
			rush += 1
			continue
		if c[i] in ma:
			if rush:
				for k in range(rush + 1):
					mo.append(ma[c[i]][-1] + 1)
				rush = 0
			else:
				mo.append(ma[c[i]][-1] + 1)
	if len(uma) or rush:
		print('NO')
	else:
		print('YES')
		print(*mo)


from collections import Counter
from collections import defaultdict
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	c = list(map(int, input().split()))
	d = Counter(b)
	s = defaultdict(int)
	ans = []
	dp = [[] for i in range(n + 1)]
	for i in range(n):
		if a[i] != b[i]:
			dp[b[i]].append(i)
	if d[c[-1]] > 0:
		if len(dp[c[-1]]) != 0:
			j = dp[c[-1]][-1]
			dp[c[-1]].pop()
		else:
			j = b.index(c[-1])
		for i in range(n):
			if a[i] != b[i]:
				s[b[i]] += 1
		for i in range(k):
			if s[c[i]] > 0:
				s[c[i]] -= 1
				if len(dp[c[i]]) == 0 or i == k - 1:
					ans.append(j + 1)
				else:
					ans.append(dp[c[i]][-1] + 1)
					dp[c[i]].pop()
			else:
				ans.append(j + 1)
		t = 0
		if len(s) > 0:
			for i in s:
				if s[i] > 0:
					t = 1
					break
		if t == 0:
			print('YES')
			print(*ans)
		else:
			print('NO')
	else:
		print('NO')


import sys
import heapq
import math
from collections import deque
MOD = 1000000007

def primes(n):
	sieve = [True] * n
	for i in range(3, int(n ** 0.5) + 1, 2):
		if sieve[i]:
			sieve[i * i::2 * i] = [False] * ((n - i * i - 1) // (2 * i) + 1)
	return [2] + [i for i in range(3, n, 2) if sieve[i]]

def factor(n, l, d):
	F = False
	for p in l:
		if n % p == 0:
			if p in d:
				d[p] += 1
			else:
				d[p] = 1
			F = True
			break
	if F:
		factor(n // p, l, d)

def find(parent, i):
	if parent[i] != i:
		parent[i] = find(parent, parent[i])
	return parent[i]

def union(parent, rank, xx, yy):
	x = find(parent, xx)
	y = find(parent, yy)
	if rank[x] > rank[y]:
		parent[y] = x
	elif rank[y] > rank[x]:
		parent[x] = y
	else:
		parent[y] = x
		rank[x] += 1
ans = 0
n = int(sys.stdin.readline().strip())
dd = {'R': 'L', 'L': 'R'}
l = [0, 0, 1, 1, 3]
for testj in range(n):
	ans = 0
	c = 1.0
	pre = [0]
	AB = sys.stdin.readline().strip().split()
	n = int(AB[0])
	k = int(AB[1])
	s0 = list(sys.stdin.readline().strip().split())
	for i in range(n):
		s0[i] = int(s0[i])
	s1 = list(sys.stdin.readline().strip().split())
	for i in range(n):
		s1[i] = int(s1[i])
	pt = list(sys.stdin.readline().strip().split())
	for i in range(k):
		pt[i] = int(pt[i])
	h = []
	F = True
	dnew = {}
	dold = {}
	snew = set()
	sold = set()
	ansl = [[] for i in range(n)]
	for i in range(n):
		if s1[i] != s0[i]:
			if s1[i] not in dnew:
				dnew[s1[i]] = [i]
			else:
				dnew[s1[i]].append(i)
		elif s1[i] not in dold:
			dold[s1[i]] = [i]
		else:
			dold[s1[i]].append(i)
	pt.reverse()
	pre = -1
	for i in range(len(pt)):
		pp = pt[i]
		if pp in dnew:
			t = dnew[pp].pop()
			ansl[t].append(i)
			if len(dnew[pp]) == 0:
				del dnew[pp]
			pre = t
			F = False
		elif pp in dold:
			ansl[dold[pp][-1]].append(i)
			pre = dold[pp][-1]
			F = False
		elif not F:
			ansl[pre].append(i)
		else:
			break
	if F or len(dnew) > 0:
		print('NO')
	else:
		print('YES')
		ans = [-1 for i in range(k)]
		for j in range(n):
			t = ansl[j]
			for i in t:
				ans[k - 1 - i] = str(j + 1)
		print(' '.join(ans))


from collections import defaultdict, OrderedDict, Counter
from sys import stdin, stdout
from bisect import bisect_left, bisect_right
from queue import Queue, PriorityQueue
from heapq import heapify, heappop, heappush
from statistics import median
from math import gcd, sqrt, floor, factorial, ceil, log2, log10
import fractions
import copy
from copy import deepcopy
import sys
sys.setrecursionlimit(10 ** 7)
import math
import os
import bisect
import collections
mod = pow(10, 9) + 7
import random
from random import random, randint, randrange

def ncr(n, r, p=mod):
	num = den = 1
	for i in range(r):
		num = num * (n - i) % p
		den = den * (i + 1) % p
	return num * pow(den, p - 2, p) % p
inf = float('inf')
adj = defaultdict(set)
visited = defaultdict(int)

def addedge(a, b):
	adj[a].add(b)
	adj[b].add(a)

def bfs(v):
	q = Queue()
	q.put(v)
	visited[v] = 1
	while q.qsize() > 0:
		s = q.get_nowait()
		print(s)
		for i in adj[s]:
			if visited[i] == 0:
				q.put(i)
				visited[i] = 1

def dfs(v, visited):
	if visited[v] == 1:
		return
	visited[v] = 1
	print(v)
	for i in adj[v]:
		dfs(i, visited)

def reverse_bisect_right(a, x, lo=0, hi=None):
	if lo < 0:
		raise ValueError('lo must be non-negative')
	if hi is None:
		hi = len(a)
	while lo < hi:
		mid = (lo + hi) // 2
		if x > a[mid]:
			hi = mid
		else:
			lo = mid + 1
	return lo

def reverse_bisect_left(a, x, lo=0, hi=None):
	if lo < 0:
		raise ValueError('lo must be non-negative')
	if hi is None:
		hi = len(a)
	while lo < hi:
		mid = (lo + hi) // 2
		if x >= a[mid]:
			hi = mid
		else:
			lo = mid + 1
	return lo

class MaxHeap:

	def _init_(self, maxsize):
		self.maxsize = maxsize
		self.size = 0
		self.Heap = [0] * (self.maxsize + 1)
		self.Heap[0] = sys.maxsize
		self.FRONT = 1

	def parent(self, pos):
		return pos // 2

	def leftChild(self, pos):
		return 2 * pos

	def rightChild(self, pos):
		return 2 * pos + 1

	def isLeaf(self, pos):
		if pos >= self.size // 2 and pos <= self.size:
			return True
		return False

	def swap(self, fpos, spos):
		(self.Heap[fpos], self.Heap[spos]) = (self.Heap[spos], self.Heap[fpos])

	def maxHeapify(self, pos):
		if not self.isLeaf(pos):
			if self.Heap[pos] < self.Heap[self.leftChild(pos)] or self.Heap[pos] < self.Heap[self.rightChild(pos)]:
				if self.Heap[self.leftChild(pos)] > self.Heap[self.rightChild(pos)]:
					self.swap(pos, self.leftChild(pos))
					self.maxHeapify(self.leftChild(pos))
				else:
					self.swap(pos, self.rightChild(pos))
					self.maxHeapify(self.rightChild(pos))

	def insert(self, element):
		if self.size >= self.maxsize:
			return
		self.size += 1
		self.Heap[self.size] = element
		current = self.size
		while self.Heap[current] > self.Heap[self.parent(current)]:
			self.swap(current, self.parent(current))
			current = self.parent(current)

	def Print(self):
		for i in range(1, self.size // 2 + 1):
			print(' PARENT : ' + str(self.Heap[i]) + ' LEFT CHILD : ' + str(self.Heap[2 * i]) + ' RIGHT CHILD : ' + str(self.Heap[2 * i + 1]))

	def extractMax(self):
		popped = self.Heap[self.FRONT]
		self.Heap[self.FRONT] = self.Heap[self.size]
		self.size -= 1
		self.maxHeapify(self.FRONT)
		return popped

def get_list():
	return list(map(int, input().split()))

def get_str_list_in_int():
	return [int(i) for i in list(input())]

def get_str_list():
	return list(input())

def get_map():
	return map(int, input().split())

def input_int():
	return int(input())

def matrix(a, b):
	return [[0 for i in range(b)] for j in range(a)]

def swap(a, b):
	return (b, a)

def find_gcd(l):
	a = l[0]
	for i in range(len(l)):
		a = gcd(a, l[i])
	return a

def is_prime(n):
	sqrta = int(sqrt(n))
	for i in range(2, sqrta + 1):
		if n % i == 0:
			return 0
	return 1

def prime_factors(n):
	sqrta = int(sqrt(n))
	for i in range(2, sqrta + 1):
		if n % i == 0:
			return [i] + prime_factors(n // i)
	return [n]
nc = 'NO'
yc = 'YES'
ns = 'No'
ys = 'Yes'

def not_possible():
	for i in ccount:
		if i in bcount:
			return 1
	return 0
t = input_int()
hi = 1
for i in range(t):
	(n, m) = get_map()
	a = get_list()
	b = get_list()
	c = get_list()
	bcount = Counter(b)
	ccount = Counter(c)
	if not not_possible():
		print(nc)
		continue
	bindex = defaultdict(list)
	cindex = defaultdict(list)
	for i in range(len(b)):
		bindex[b[i]].append(i)
	for i in range(len(c)):
		cindex[c[i]].append(i)
	arr1 = [0] * m
	for i in range(m):
		if c[i] in bindex:
			arr1[i] = bindex[c[i]][0] + 1
		else:
			arr1[i] = inf
	possible = 1
	seta = set()
	used = defaultdict(int)
	for i in range(n):
		if a[i] != b[i]:
			if b[i] not in ccount:
				possible = 0
			if b[i] in cindex:
				indexa = cindex[b[i]].pop()
				if len(cindex[b[i]]) == 0:
					cindex.pop(b[i])
				arr1[indexa] = i + 1
				a[i] = b[i]
				continue
			seta.add(i)
	if possible == 0:
		print(nc)
		continue
	if arr1[-1] == inf:
		print(nc)
		continue
	while inf in arr1:
		for i in range(m - 1):
			if arr1[i] == inf:
				arr1[i] = arr1[i + 1]
	if len(seta):
		print(nc)
		continue
	if a != b:
		print(nc)
		continue
	print(yc)
	print(*arr1)


from collections import *
a = int(input())
for i in range(a):
	(n, m) = map(int, input().split())
	ori = list(map(int, input().split()))
	fin = list(map(int, input().split()))
	painter = list(map(int, input().split()))
	lite = []
	imp = []
	crud = defaultdict(int)
	check = defaultdict(int)
	al = defaultdict(list)
	for i in range(len(ori)):
		if ori[i] == fin[i]:
			lite.append([fin[i], i])
		else:
			imp.append([fin[i], i])
			crud[i] = 1
	for i in range(len(lite)):
		al[lite[i][0]].append(lite[i][1])
	for i in range(len(imp)):
		al[imp[i][0]].append(imp[i][1])
	flag = -2
	pri = [0 for i in range(len(painter))]
	for i in range(len(painter) - 1, -1, -1):
		if len(al[painter[i]]):
			t = al[painter[i]][-1]
			flag = t + 1
			if crud[t] == 1:
				pri[i] = t + 1
				ori[al[painter[i]][-1]] = painter[i]
				al[painter[i]].pop()
				continue
			pri[i] = t + 1
		elif flag > 0:
			pri[i] = flag
		else:
			flag = -2
			break
	if flag == -2:
		print('NO')
	else:
		flag = 0
		for i in range(len(ori)):
			if ori[i] != fin[i]:
				flag = 1
				break
		if flag == 0:
			print('YES')
			print(*pri)
		else:
			print('NO')


import sys
input = sys.stdin.readline
import math
import copy
import collections
from collections import deque
import heapq
import itertools
from collections import defaultdict
from collections import Counter
for _ in range(int(input())):
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	c = list(map(int, input().split()))
	d = defaultdict(lambda : set())
	for i in range(n):
		if b[i] != a[i]:
			d[b[i]].add(i)
	safe = -1
	poss = False
	if c[m - 1] in d:
		safe = d[c[m - 1]].pop()
		poss = True
	if safe == -1:
		for i in range(n):
			if b[i] == c[m - 1]:
				safe = i
				poss = True
				break
	ans = []
	for i in range(m - 1):
		if c[i] in d:
			if len(d[c[i]]) > 0:
				ans.append(d[c[i]].pop())
			else:
				ans.append(safe)
		else:
			ans.append(safe)
	ans.append(safe)
	for key in d:
		if len(d[key]) != 0:
			poss = False
	if poss:
		print('YES')
		for num in ans:
			print(num + 1, end=' ')
		print()
	else:
		print('NO')


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	c = list(map(int, input().split()))
	last = c[-1]
	if last in b:
		idx = -1
		for i in range(n):
			if b[i] == last:
				idx = i
				break
		ch = [[] for i in range(n + 1)]
		ans = [-1 for i in range(m)]
		for i in range(n):
			if a[i] != b[i]:
				ch[b[i]].append(i + 1)
		if ch[last]:
			ans[-1] = ch[last].pop()
			idx = ans[-1] - 1
		else:
			ans[-1] = idx + 1
		for i in range(m - 1):
			if ch[c[i]]:
				ans[i] = ch[c[i]].pop()
			else:
				ans[i] = idx + 1
		if all((not ch[i] for i in range(n + 1))):
			print('YES')
			print(*ans)
		else:
			print('NO')
	else:
		print('NO')


for t in range(int(input())):
	(n, m) = map(int, input().split())
	colors = [[] for i in range(n + 1)]
	pos = 0
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	for i in range(n):
		if a[i] == b[i]:
			colors[b[i]].append(i)
	for i in range(n):
		if a[i] != b[i]:
			colors[b[i]].append(i)
	mm = list(map(int, input().split()))
	if len(colors[mm[-1]]) == 0:
		print('NO')
		continue
	lastpos = colors[mm[-1]][-1]
	ans = [0] * m
	for i in range(m - 1, -1, -1):
		c = mm[i]
		if len(colors[c]) == 0:
			ans[i] = lastpos
		elif len(colors[c]) == 1:
			ans[i] = colors[c][0]
		else:
			ans[i] = colors[c].pop()
	for i in range(m):
		a[ans[i]] = mm[i]
	if a == b:
		print('YES\n' + ' '.join([str(i + 1) for i in ans]))
	else:
		print('NO')


import os, io
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	c = list(map(int, input().split()))
	final = c[-1]
	flag = -1
	for i in range(n):
		if b[i] == final and a[i] != b[i]:
			flag = i
			break
	if flag == -1:
		for i in range(n):
			if b[i] == final:
				flag = i
				break
	if flag == -1:
		print('NO')
		continue
	grid = []
	for i in range(n + 1):
		grid.append([])
	for i in range(n):
		if i == flag:
			continue
		if a[i] != b[i]:
			grid[b[i]].append(i)
	ans = []
	for i in range(k - 1):
		if grid[c[i]]:
			t = grid[c[i]].pop()
			ans.append(t + 1)
		else:
			ans.append(flag + 1)
	ans.append(flag + 1)
	fail = 0
	for i in range(n + 1):
		if grid[i]:
			fail = 1
			break
	if fail:
		print('NO')
		continue
	print('YES')
	print(' '.join(map(str, ans)))


import sys
input = sys.stdin.buffer.readline
ri = lambda : int(input())
rl = lambda : list(map(int, input().split()))
rs = lambda : input().decode().rstrip('\n\r')
wrt = sys.stdout.write
pr = lambda *args, end='\n': wrt(' '.join([str(x) for x in args]) + end)
xrange = lambda *args: reversed(range(*args))
cdiv = lambda x, y: -(-x // y)
enum = enumerate
inf = float('inf')
mod = 10 ** 9 + 7
from collections import defaultdict as dd, Counter
from queue import deque
Testcase = ri()
for testcase in range(Testcase):
	(n, m) = rl()
	a = rl()
	b = rl()
	c = rl()
	color = dd(list)
	for i in range(n):
		if a[i] != b[i]:
			color[b[i]].append(i)
	ans = [-1 for i in range(m)]
	extra = []
	for i in range(m - 1):
		paint = c[i]
		if color[paint]:
			plank = color[paint].pop()
			ans[i] = plank
			a[plank] = paint
		else:
			extra.append(i)
	paint = c[-1]
	plank = -1
	if color[paint]:
		plank = color[paint].pop()
	elif paint in a:
		plank = a.index(paint)
	if plank == -1:
		print('NO')
	else:
		for i in extra:
			ans[i] = plank
			a[plank] = paint
		ans[-1] = plank
		a[plank] = paint
		if a != b:
			print('NO')
		else:
			print('YES')
			print(*[i + 1 for i in ans])


from collections import Counter, defaultdict
from sys import stdin
readline = stdin.readline

def read_ints():
	return map(int, readline().split())

def f(a_seq, b_seq, c_seq):
	assert len(a_seq) == len(b_seq)
	n = len(a_seq)
	colors_need = Counter((b for (a, b) in zip(a_seq, b_seq) if a != b))
	colors_has = Counter(c_seq)
	if any((colors_has[c] < required_n for (c, required_n) in colors_need.items())):
		raise ValueError
	indices_by_required_colors = defaultdict(list)
	for i in range(n):
		if b_seq[i] != a_seq[i]:
			indices_by_required_colors[b_seq[i]].append(i)
	if c_seq[-1] not in b_seq:
		raise ValueError
	if c_seq[-1] in indices_by_required_colors:
		i_swap = indices_by_required_colors[c_seq[-1]][0]
	else:
		i_swap = b_seq.index(c_seq[-1])
	for c in c_seq:
		if c in indices_by_required_colors:
			yield indices_by_required_colors[c].pop()
			if not indices_by_required_colors[c]:
				del indices_by_required_colors[c]
		else:
			yield i_swap
(t_n,) = read_ints()
for i_t in range(t_n):
	(n, m) = read_ints()
	a_seq = tuple(read_ints())
	b_seq = tuple(read_ints())
	c_seq = tuple(read_ints())
	try:
		result = tuple(f(a_seq, b_seq, c_seq))
	except ValueError:
		print('NO')
	else:
		print('YES')
		print(*[i + 1 for i in result])


import sys
import math
from collections import defaultdict, Counter, deque
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
t = int(input())
for i in range(t):
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	c = list(map(int, input().split()))
	d1 = defaultdict(list)
	d2 = {}
	for j in range(n):
		if a[j] != b[j]:
			d1[b[j]].append(j + 1)
		else:
			d2[b[j]] = j + 1
	ans = [0] * m
	last = -1
	flag = 1
	for j in range(m):
		if d1[c[j]]:
			ans[j] = d1[c[j]].pop()
			if len(d1[c[j]]) == 0:
				d2[c[j]] = ans[j]
		elif d2.get(c[j]) != None:
			ans[j] = d2[c[j]]
		else:
			last = j
	for j in d1:
		if len(d1[j]) > 0:
			flag = 0
			break
	if flag == 0 or last == m - 1:
		print('NO')
	else:
		print('YES')
		for j in ans:
			if j == 0:
				print(ans[-1], end=' ')
			else:
				print(j, end=' ')
		print()


def solveTestCase():
	nm = [int(i) for i in input().split()]
	A = [int(i) for i in input().split()]
	B = [int(i) for i in input().split()]
	C = [int(i) for i in input().split()]
	to_change = {}
	last_couleur = C[-1]
	for_last = 0
	last_mod = 0
	to_mod = 0
	for i in range(len(A)):
		if A[i] != B[i]:
			to_mod += 1
			if B[i] not in to_change:
				to_change[B[i]] = []
			to_change[B[i]].append(i + 1)
			if B[i] == last_couleur:
				last_mod = i + 1
		if B[i] == last_couleur:
			for_last = i + 1
	if last_mod != 0:
		for_last = last_mod
	if for_last == 0:
		print('NO')
		return
	if to_mod > nm[1]:
		print('NO')
		return
	res = []
	for i in range(len(C)):
		if C[i] not in to_change or len(to_change[C[i]]) == 0:
			res.append(for_last)
		else:
			res.append(to_change[C[i]].pop(0))
	for (k, v) in to_change.items():
		if len(v) != 0:
			print('NO')
			return
	print('YES')
	for i in res:
		print(i, end=' ')
	print()
t = int(input().split()[0])
while t > 0:
	t -= 1
	solveTestCase()


def zip_sorted(a, b):
	(a, b) = zip(*sorted(zip(a, b)))
	sorted(zip(a, b), key=lambda x: x[1])
	return (a, b)
import sys
from collections import defaultdict
input = sys.stdin.readline
I = lambda : list(map(int, input().split()))
S = lambda : list(map(str, input().split()))
(t,) = I()
for t1 in range(t):
	(n, m) = I()
	a = I()
	b = I()
	c = I()
	count = 0
	order = []
	no_of_painter_req = [[] for i in range(n + 1)]
	last_index_paint = [-1 for i in range(n + 1)]
	order = []
	for i in range(len(a)):
		if a[i] == b[i]:
			last_index_paint[b[i]] = i
		else:
			no_of_painter_req[b[i]].append(i)
	if no_of_painter_req[c[-1]] == [] and last_index_paint[c[-1]] == -1:
		print('NO')
	else:
		order = []
		last_index = -1
		for i in range(len(c) - 1, -1, -1):
			if no_of_painter_req[c[i]] != []:
				last_index = no_of_painter_req[c[i]].pop()
				order.append(last_index + 1)
			elif last_index_paint[c[i]] != -1:
				last_index = last_index_paint[c[i]]
				order.append(last_index + 1)
			else:
				order.append(last_index + 1)
		order = list(reversed(order))
		temp = [b[i] for i in range(len(b))]
		for i in range(len(c)):
			temp[order[i] - 1] = c[i]
		count = 0
		for i in range(len(no_of_painter_req)):
			if no_of_painter_req[i] != []:
				count = 1
				break
		if count == 1:
			print('NO')
		else:
			print('YES')
			print(*order)


t = int(input())
for test in range(t):
	(n, m) = map(int, input().split())
	need = [0] * n
	check = [0] * n
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	c = list(map(int, input().split()))
	d = dict()
	for i in range(n):
		if a[i] != b[i]:
			if b[i] not in d:
				d[b[i]] = [i + 1]
			else:
				d[b[i]].append(i + 1)
			need[b[i] - 1] += 1
		check[b[i] - 1] += 1
	have = [0] * n
	for i in range(m):
		have[c[i] - 1] += 1
	flag = True
	for i in range(n):
		flag = flag and need[i] <= have[i]
	if not flag:
		print('NO')
		continue
	if not check[c[-1] - 1]:
		print('NO')
	else:
		print('YES')
		trash = c[-1]
		if trash not in d:
			trash = b.index(trash) + 1
		else:
			trash = d[trash][0]
		for i in range(m):
			if i == m - 1:
				print(trash)
				break
			if need[c[i] - 1]:
				need[c[i] - 1] -= 1
				print(d[c[i]][-1], end=' ')
				d[c[i]].pop()
			else:
				print(trash, end=' ')


import sys
import os
import math
sys.setrecursionlimit(100000)

def testcase():
	(n, m) = [int(w) for w in input().split()]
	org = [int(w) for w in input().split()]
	new = [int(w) for w in input().split()]
	painters = [int(w) for w in input().split()]
	painters.reverse()
	exists = set(new)
	idx_dict = {}
	for i in range(len(new)):
		idx_dict[new[i]] = i
	diff = [0 if org[i] == new[i] else new[i] for i in range(n)]
	needs = {}
	needs_idx = {}
	needs_cnt = 0
	for i in range(len(diff)):
		d = diff[i]
		if d == 0:
			continue
		if d not in needs.keys():
			needs[d] = 0
			needs_idx[d] = []
		needs[d] += 1
		needs_idx[d].append(i)
		needs_cnt += 1
	removed = False
	orders = []
	for c in painters:
		if c in exists:
			if c in needs.keys() and needs[c] > 0:
				needs[c] -= 1
				needs_cnt -= 1
				idx = needs_idx[c][-1]
				needs_idx[c].pop()
				orders.append(idx)
			else:
				orders.append(idx_dict[c])
			removed = True
		elif not removed:
			print('NO')
			return
		else:
			orders.append(orders[-1])
	if needs_cnt == 0:
		print('YES')
		print(' '.join([str(w + 1) for w in reversed(orders)]))
	else:
		print('NO')
tc = int(input())
for _ in range(tc):
	testcase()


from sys import stdin
from math import ceil
input = stdin.readline

def main():
	t = int(input())
	for i in range(t):
		(n, m) = map(int, input().split())
		ai = list(map(int, input().split()))
		bi = list(map(int, input().split()))
		ais = {}
		bs = {}
		ar = {}
		for i in range(n + 1):
			ais[i] = []
			bs[i] = []
			ar[i] = [1]
		for i in range(n):
			bs[bi[i]] += [i + 1]
			if ai[i] != bi[i]:
				ar[bi[i]] += [i + 1]
			else:
				ais[ai[i]] += [i + 1]
		ci = list(map(int, input().split()))
		anss = [0] * m
		ans = 1
		prev = -1
		for i in range(m - 1, -1, -1):
			temp = ar[ci[i]]
			if temp[0] == len(temp):
				if prev != -1:
					anss[i] = prev
				else:
					temp2 = ais[ci[i]]
					if len(temp2) != 0:
						anss[i] = temp2[0]
					else:
						temp2 = bs[ci[i]]
						if len(temp2) != 0:
							anss[i] = temp2[0]
						else:
							ans = 0
							break
			else:
				anss[i] = temp[temp[0]]
				temp[0] += 1
			prev = anss[m - 1]
		for i in range(n + 1):
			temp = ar[i]
			if temp[0] != len(temp):
				ans = 0
				break
		if ans == 1:
			print('YES')
			print(' '.join(map(str, anss)))
		else:
			print('NO')
main()


import sys, math
import io, os
from bisect import bisect_left as bl, bisect_right as br, insort
from heapq import heapify, heappush, heappop
from collections import defaultdict as dd, deque, Counter
from itertools import permutations, combinations

def data():
	return sys.stdin.readline().strip()

def mdata():
	return list(map(int, data().split()))

def outl(var):
	sys.stdout.write(' '.join(map(str, var)) + '\n')

def out(var):
	sys.stdout.write(str(var) + '\n')
from decimal import Decimal
from fractions import Fraction
INF = float('inf')
mod = 10 ** 9 + 7
for t in range(int(data())):
	(n, m) = mdata()
	a = mdata()
	b = mdata()
	c = mdata()
	d = dd(list)
	ind = -1
	for i in range(n):
		if c[-1] == b[i] and b[i] != a[i]:
			ind = i
		if a[i] != b[i]:
			d[b[i]].append(i)
	if ind == -1:
		for i in range(n):
			if c[-1] == b[i]:
				ind = i
	if ind == -1:
		out('NO')
	else:
		d[c[-1]].reverse()
		ans = [0] * m
		for i in range(m):
			if d[c[i]]:
				k = d[c[i]].pop()
			else:
				k = ind
			ans[i] = k + 1
			a[k] = c[i]
		if a == b:
			out('YES')
			outl(ans)
		else:
			out('NO')


import sys
from collections import defaultdict, Counter

def read_ints():
	return [int(i) for i in sys.stdin.readline().strip().split()]

def read_int():
	return int(sys.stdin.readline().strip())

def solve(n, m, fence, desired, painters):
	paints = defaultdict(list)
	last = dict()
	if painters[-1] not in desired:
		print('NO')
		return
	painters_ctr = Counter(painters)
	for (i, (oldc, newc)) in enumerate(zip(fence, desired)):
		if newc != oldc:
			paints[newc].append(i + 1)
		last[newc] = i + 1
	for (colour, planks) in paints.items():
		if painters_ctr[colour] < len(planks):
			print('NO')
			return
	print('YES')
	output = []
	encountered = Counter()
	for colour in painters:
		nseen = encountered[colour]
		if not paints[colour]:
			to_paint = last.get(colour, -1)
		elif nseen >= len(paints[colour]):
			to_paint = paints[colour][-1]
		else:
			to_paint = paints[colour][nseen]
		output.append(to_paint)
		encountered[colour] += 1
	last_plank = output[-1]
	print(' '.join((str(last_plank if c == -1 else c) for c in output)))
ncases = read_int()
for i in range(ncases):
	(n, m) = read_ints()
	fence = read_ints()
	desired = read_ints()
	painters = read_ints()
	solve(n, m, fence, desired, painters)


t = int(input())
for _ in range(t):
	(n, k) = [int(i) for i in input().split()]
	a = [int(i) for i in input().split()]
	b = [int(i) for i in input().split()]
	c = [int(i) for i in input().split()]
	d = {}
	d1 = {}
	for i in range(n):
		if a[i] != b[i]:
			if b[i] not in d:
				d[b[i]] = []
			d[b[i]].append(i + 1)
		d1[b[i]] = i + 1
	ans = []
	for i in range(k):
		ans.append(0)
	for i in range(k):
		if c[i] in d:
			ans[i] = d[c[i]][0]
			d[c[i]].pop(0)
			if len(d[c[i]]) == 0:
				d.pop(c[i])
		elif c[i] in d1:
			ans[i] = d1[c[i]]
	if len(d) != 0:
		print('NO')
	else:
		last = -1
		for i in range(k - 1, -1, -1):
			if ans[i] == 0:
				if last == -1 and c[i] not in d1:
					print('NO')
					break
				elif last != -1:
					ans[i] = last
				else:
					ans[i] = d1[c[i]]
			else:
				last = ans[i]
		else:
			print('YES')
			for i in ans:
				print(i, end=' ')
			print()


import sys
from collections import defaultdict as dd
from collections import Counter as cc
from queue import Queue
import math
import itertools
try:
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
except:
	pass
input = lambda : sys.stdin.readline().rstrip()
for _ in range(int(input())):
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	c = list(map(int, input().split()))
	q = dd(int)
	w = dd(list)
	k = -1
	r = [0] * m
	f = 0
	for i in range(n):
		if k == -1 and c[-1] == b[i]:
			k = i
		if b[i] == a[i]:
			b[i] = -1
		else:
			w[b[i]].append(i)
			q[b[i]] += 1
			f += 1
	if k != -1:
		for i in range(m):
			if q[c[i]] > 0:
				q[c[i]] -= 1
				f -= 1
				r[i] = w[c[i]].pop() + 1
			else:
				r[i] = -1
		if r[-1] == -1:
			r[-1] = k + 1
		for i in range(m):
			if r[i] == -1:
				r[i] = r[-1]
		if f > 0:
			print('NO')
		else:
			print('YES')
			print(*r)
	else:
		print('NO')


import sys
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	a = [int(item) for item in input().split()]
	b = [int(item) for item in input().split()]
	c = [int(item) for item in input().split()]
	color_place = [-1] * n
	to_recolor = [[] for _ in range(n)]
	for (i, (aa, bb)) in enumerate(zip(a, b)):
		if aa != bb:
			to_recolor[bb - 1].append(i)
		color_place[bb - 1] = i
	ans = []
	for (i, cc) in enumerate(c):
		if len(to_recolor[cc - 1]) > 0:
			ans.append(to_recolor[cc - 1].pop() + 1)
		else:
			ans.append(None)
	dump_place = -1
	ok = True
	for i in range(n):
		if len(to_recolor[i]) > 0:
			ok = False
	if not ok:
		print('NO')
		continue
	if ans[-1] == None:
		if color_place[c[-1] - 1] == -1:
			print('NO')
			continue
		else:
			dump_place = color_place[c[-1] - 1] + 1
	else:
		dump_place = ans[-1]
	for i in range(len(c)):
		if ans[i] == None:
			ans[i] = dump_place
	print('YES')
	print(*ans)


import sys
import math
import bisect
import functools
from functools import lru_cache
from sys import stdin, stdout
from math import gcd, floor, sqrt, log, ceil
from heapq import heappush, heappop, heapify
from collections import defaultdict as dd
from collections import Counter as cc
from bisect import bisect_left as bl
from bisect import bisect_right as br

def lcm(a, b):
	return abs(a * b) // math.gcd(a, b)
sys.setrecursionlimit(100000000)
intinp = lambda : int(input().strip())
stripinp = lambda : input().strip()
fltarr = lambda : list(map(float, input().strip().split()))
intarr = lambda : list(map(int, input().strip().split()))
ceildiv = lambda x, d: x // d if x % d == 0 else x // d + 1
MOD = 1000000007
num_cases = intinp()
for _ in range(num_cases):
	(n, m) = intarr()
	ar = intarr()
	arr = intarr()
	ac = intarr()
	c = dd(list)
	need = dd(set)
	curr = dd(set)
	stand = []
	ans = [-1] * m
	for (v, [i, d]) in enumerate(list(zip(ar, arr))):
		if i != d:
			need[d].add(v)
		curr[i].add(v)
	for (i, v) in enumerate(ac):
		if v in need:
			val = need[v].pop()
			ans[i] = val + 1
			for (ind, col) in stand:
				ans[ind] = val + 1
			stand = []
			curr[ar[val]].remove(val)
			curr[v].add(val)
			if not need[v]:
				del need[v]
			if not curr[ar[val]]:
				del curr[ar[val]]
		elif v in curr:
			val = curr[v].pop()
			ans[i] = val + 1
			curr[v].add(val)
			for (ind, col) in stand:
				ans[ind] = val + 1
			stand = []
		else:
			stand.append([i, v])
	if not stand and (not need):
		print('YES')
		for v in ans:
			print(v, end=' ')
		print()
	else:
		print('NO')


def solve(n, m, a, b, c):
	d = {}
	good = {}
	cnt = {}
	for i in range(n):
		if a[i] == b[i]:
			good[b[i]] = i
		elif b[i] not in d:
			d[b[i]] = [i]
			cnt[b[i]] = 1
		else:
			d[b[i]].append(i)
			cnt[b[i]] += 1
	fallback = -1
	p = []
	for i in range(m - 1, -1, -1):
		if c[i] in cnt:
			if cnt[c[i]]:
				cnt[c[i]] -= 1
			p.append(d[c[i]][cnt[c[i]]] + 1)
			fallback = p[-1]
		elif c[i] in good:
			p.append(good[c[i]] + 1)
			fallback = p[-1]
		elif fallback == -1:
			print('NO')
			return
		else:
			p.append(fallback)
	for k in cnt:
		if cnt[k]:
			print('NO')
			return
	print('YES')
	print(*p[::-1])

def main():
	t = int(input())
	for _ in range(t):
		(n, m) = map(int, input().split())
		a = list(map(int, input().split()))
		b = list(map(int, input().split()))
		c = list(map(int, input().split()))
		solve(n, m, a, b, c)
main()


p = lambda : list(map(int, input().split()))
r = print
g = range
l = len
for _ in '.' * p()[0]:
	(N, M) = p()
	L = N + 1
	A = p()
	B = p()
	C = p()[::-1]
	X = [[] for i in g(L)]
	Y = [[] for i in g(L)]
	for i in g(N):
		if A[i] == B[i]:
			X[A[i]].append(i + 1)
		else:
			Y[B[i]].append(i + 1)
	P = []
	for i in g(M):
		c = C[i]
		if l(Y[c]):
			P.append(Y[c].pop())
		elif i:
			P.append(P[0])
		elif l(X[c]):
			P.append(X[c][0])
		else:
			Y[0].append(-1)
			P.append(0)
	if sum([l(Y[i]) for i in g(L)]) < 1:
		r('YES')
		r(*P[::-1])
	else:
		r('NO')


import sys
input = sys.stdin.readline
from collections import deque
ansl = []
for _ in range(int(input())):
	(n, m) = map(int, input().split())
	al = list(map(int, input().split()))
	bl = list(map(int, input().split()))
	cl = list(map(int, input().split()))
	cl = cl[::-1]
	used = -1
	need_cnt = 0
	need = {b: deque() for b in bl}
	ok = {b: i for (i, b) in enumerate(bl)}
	for i in range(n):
		if al[i] != bl[i]:
			need[bl[i]].append(i)
			need_cnt += 1
	ans = []
	cnt = 0
	for c in cl:
		if c in need and need[c]:
			poped = need[c].popleft()
			ans.append(poped + 1)
			used = poped
			cnt += 1
		elif used != -1:
			ans.append(used + 1)
		elif c in ok:
			ans.append(ok[c] + 1)
			used = ok[c]
		else:
			ans = []
			break
	if cnt == need_cnt:
		ansl.append(ans[::-1])
	else:
		ansl.append([])
for row in ansl:
	if row:
		print('YES')
		print(*row)
	else:
		print('NO')


import sys, io, os
from collections import defaultdict
if os.environ['USERNAME'] == 'kissz':
	inp = open('in.txt', 'r').readline

	def debug(*args):
		print(*args, file=sys.stderr)
else:
	inp = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline

	def debug(*args):
		pass

def solve():
	(n, m) = map(int, inp().split())
	A = [*map(int, inp().split())]
	B = [*map(int, inp().split())]
	C = [*map(int, inp().split())]
	if C[-1] not in B:
		print('NO')
		return
	need = defaultdict(list)
	X = [0] * m
	for i in range(n):
		(a, b) = (A[i], B[i])
		if a != b:
			need[b] += [i]
	for i in range(m - 1, -1, -1):
		c = C[i]
		if need[c]:
			X[i] = need[c].pop() + 1
		elif i == m - 1:
			j = 0
			while B[j] != c:
				j += 1
			X[i] = j + 1
		else:
			X[i] = X[-1]
	if any(need.values()):
		print('NO')
		return
	else:
		print('YES')
		print(*X)
for _ in range(int(inp())):
	solve()


import sys
input = sys.stdin.readline
for _ in range(int(input().strip())):
	(n, m) = map(int, input().strip().split(' '))
	a = list(map(int, input().strip().split(' ')))
	b = list(map(int, input().strip().split(' ')))
	c = list(map(int, input().strip().split(' ')))
	t = {}
	tp = 0
	bd = {}
	bdc = 0
	kmata = []
	for i in range(n):
		if a[i] != b[i]:
			if b[i] not in bd:
				bd[b[i]] = []
			bd[b[i]].append(i + 1)
			kmata.append(b[i])
			bdc += 1
		if b[i] not in t:
			t[b[i]] = []
		t[b[i]].append(i + 1)
	i = 0
	j = 0
	out = []
	while bdc != 0 and i < m:
		if c[i] in bd:
			out.append(bd[c[i]].pop())
			if bd[c[i]] == []:
				del bd[c[i]]
			bdc -= 1
		else:
			while kmata[j] not in bd:
				j += 1
			out.append(bd[kmata[j]][0])
		i += 1
	kpos = []
	while i < m:
		if c[i] not in t:
			tp = 1
			kpos.append(len(out))
			out.append(0)
		elif tp > 0:
			tp -= 1
			out.append(t[c[i]][0])
			while kpos:
				out[kpos.pop()] = t[c[i]][0]
		else:
			out.append(t[c[i]][0])
		i += 1
	if tp == 0 and bdc == 0:
		print('YES')
		sys.stdout.write(' '.join(map(str, out)) + '\n')
	else:
		print('NO')


import sys
input = sys.stdin.readline
t = int(input())
for tests in range(t):
	(n, m) = map(int, input().split())
	A = list(map(int, input().split()))
	B = list(map(int, input().split()))
	C = list(map(int, input().split()))
	OK = [[] for i in range(n + 1)]
	NG = [[] for i in range(n + 1)]
	for i in range(n):
		if A[i] == B[i]:
			OK[B[i]].append(i)
		else:
			NG[B[i]].append(i)
	ANS = []
	OKflag = -1
	for i in range(m - 1, -1, -1):
		if len(NG[C[i]]) > 0:
			x = NG[C[i]].pop()
			ANS.append(x)
			OK[C[i]].append(x)
			OKflag = x
		elif len(OK[C[i]]) > 0:
			x = OK[C[i]][0]
			ANS.append(x)
			OKflag = x
		elif OKflag != -1:
			ANS.append(OKflag)
		else:
			print('NO')
			break
	else:
		for i in range(n + 1):
			if len(NG[i]) > 0:
				print('NO')
				break
		else:
			print('YES')
			print(*[a + 1 for a in ANS][::-1])


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	(N, M) = map(int, input().split())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	c = list(map(int, input().split()))
	t = [[] for _ in range(N + 1)]
	for i in range(N):
		if a[i] != b[i]:
			t[b[i]].append(i + 1)
	res = [0] * M
	same = [0] * (N + 1)
	for i in range(M):
		x = c[i]
		if len(t[x]):
			res[i] = t[x].pop()
			if len(t[x]) == 0:
				same[x] = res[i]
	for i in range(N):
		if a[i] == b[i]:
			same[a[i]] = i + 1
	for i in range(M):
		if res[i]:
			continue
		x = c[i]
		if same[x]:
			res[i] = same[x]
	for i in range(M):
		if res[i]:
			continue
		res[i] = res[-1]
	if 0 in res:
		print('NO')
		continue
	for i in range(M):
		x = c[i]
		j = res[i] - 1
		a[j] = x
	if a == b:
		print('YES')
		print(*res)
	else:
		print('NO')


from math import *
import threading
import sys
mod = 10 ** 9
inf = 10 ** 6
yes = 'YES'
no = 'NO'

def npr(n, r):
	return factorial(n) // factorial(n - r) if n >= r else 0

def ncr(n, r):
	return factorial(n) // (factorial(r) * factorial(n - r)) if n >= r else 0

def lower_bound(li, num):
	answer = -1
	start = 0
	end = len(li) - 1
	while start <= end:
		middle = (end + start) // 2
		if li[middle] >= num:
			answer = middle
			end = middle - 1
		else:
			start = middle + 1
	return answer

def upper_bound(li, num):
	answer = -1
	start = 0
	end = len(li) - 1
	while start <= end:
		middle = (end + start) // 2
		if li[middle] <= num:
			answer = middle
			start = middle + 1
		else:
			end = middle - 1
	return answer

def abs(x):
	return x if x >= 0 else -x

def binary_search(li, val, lb, ub):
	ans = -1
	while lb <= ub:
		mid = (lb + ub) // 2
		if li[mid] > val:
			ub = mid - 1
		elif val > li[mid]:
			lb = mid + 1
		else:
			ans = mid
			break
	return ans

def kadane(x):
	sum_so_far = 0
	current_sum = 0
	for i in x:
		current_sum += i
		if current_sum < 0:
			current_sum = 0
		else:
			sum_so_far = max(sum_so_far, current_sum)
	return sum_so_far

def pref(li):
	pref_sum = [0]
	for i in li:
		pref_sum.append(pref_sum[-1] + i)
	return pref_sum

def graph(n, m):
	adj = dict()
	for i in range(1, n + 1):
		adj.setdefault(i, 0)
	for i in range(m):
		(a, b) = map(int, input().split())
		adj[a] += 1
		adj[b] += 1
	return adj

def SieveOfEratosthenes(n):
	prime = [True for i in range(n + 1)]
	p = 2
	li = []
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	for p in range(2, len(prime)):
		if prime[p]:
			li.append(p)
	return li

def primefactors(n):
	factors = []
	while n % 2 == 0:
		factors.append(2)
		n //= 2
	for i in range(3, int(sqrt(n)) + 1, 2):
		while n % i == 0:
			factors.append(i)
			n //= i
	if n > 2:
		factors.append(n)
	return factors

def prod(li):
	ans = 1
	for i in li:
		ans *= i
	return ans

def dist(a, b):
	d = abs(a[1] - b[1]) + abs(a[2] - b[2])
	return d

def power_of_n(x, n):
	cnt = 0
	while x % n == 0:
		cnt += 1
		x //= n
	return cnt
import itertools
sys.setrecursionlimit(300000)
for _ in range(int(input()) if True else 1):
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	c = list(map(int, input().split()))
	reqd = [0] * (n + 1)
	ind = [[]] * (n + 1)
	available = [0] * (n + 1)
	maxreqd = [0] * (n + 1)
	lastind = [0] * (n + 1)
	for i in range(n):
		if b[i] != a[i]:
			reqd[b[i]] += 1
			ind[b[i]] = ind[b[i]] + [i + 1]
		maxreqd[b[i]] += 1
		lastind[b[i]] = i + 1
	f = 1
	for i in range(m):
		available[c[i]] += 1
	for i in range(n + 1):
		if available[i] < reqd[i]:
			f = 0
	if maxreqd[c[-1]] == 0:
		f = 0
	if f == 0:
		print(no)
		continue
	print(yes)
	if len(ind[c[m - 1]]) != 0:
		arbitrary = ind[c[-1]][-1]
	else:
		arbitrary = lastind[c[m - 1]]
	for i in range(m):
		if len(ind[c[i]]) == 0:
			print(arbitrary, end=' ')
		else:
			print(ind[c[i]][0], end=' ')
			ind[c[i]] = ind[c[i]][1:]
	print('')


import os
import sys
from io import BytesIO, IOBase
import heapq as h
from bisect import bisect_left, bisect_right
import time
from types import GeneratorType
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		import os
		self.os = os
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = self.os.read(self._fd, max(self.os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = self.os.read(self._fd, max(self.os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			self.os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
from collections import defaultdict as dd, deque as dq, Counter as dc
import math, string

def getInts():
	return [int(s) for s in input().split()]

def getInt():
	return int(input())

def getStrs():
	return [s for s in input().split()]

def getStr():
	return input()

def listStr():
	return list(input())

def getMat(n):
	return [getInts() for _ in range(n)]

def isInt(s):
	return '0' <= s[0] <= '9'
MOD = 10 ** 9 + 7

def solve():
	(N, M) = getInts()
	A = getInts()
	B = getInts()
	C = getInts()
	must = dd(list)
	could = dd(int)
	for i in range(N):
		if A[i] == B[i]:
			could[B[i]] = i + 1
		else:
			must[B[i]].append(i + 1)
			could[B[i]] = i + 1
	ans = [-1] * M
	painted = -1
	for i in range(M - 1, -1, -1):
		if must[C[i]]:
			ans[i] = must[C[i]].pop()
			if painted == -1:
				painted = ans[i]
		elif could[C[i]] > 0:
			ans[i] = could[C[i]]
			if painted == -1:
				painted = ans[i]
		elif painted == -1:
			print('NO')
			return
		else:
			ans[i] = painted
	for key in must:
		if len(must[key]) > 0:
			print('NO')
			return
	print('YES')
	print(*ans)
	return
for _ in range(getInt()):
	solve()


import sys
import io, os
input = sys.stdin.buffer.readline
t = int(input())
from collections import defaultdict
for _ in range(t):
	(n, m) = map(int, input().split())
	A = list(map(int, input().split()))
	B = list(map(int, input().split()))
	C = list(map(int, input().split()))
	A = [a - 1 for a in A]
	B = [b - 1 for b in B]
	C = [c - 1 for c in C]
	X = [[] for i in range(n)]
	Y = defaultdict(lambda : [])
	for (i, (a, b)) in enumerate(zip(A, B)):
		if a != b:
			X[b].append(i)
		else:
			Y[b].append(i)
	ok = []
	flag = True
	ans = [-1] * m
	for i in reversed(range(m)):
		c = C[i]
		if not X[c]:
			if Y[c]:
				ans[i] = Y[c][0]
				ok.append(Y[c][0])
			elif not ok:
				flag = False
				break
			else:
				ans[i] = ok[0]
		else:
			j = X[c].pop()
			ans[i] = j
			ok.append(j)
	for i in range(n):
		if X[i]:
			flag = False
	if flag:
		print('YES')
		ans = [i + 1 for i in ans]
		print(*ans)
	else:
		print('NO')


import sys
import math
from sys import stdin, stdout

def sieve(N):
	primeNumbers = [True] * (N + 1)
	primeNumbers[0] = False
	primeNumbers[1] = False
	i = 2
	while i * i <= N:
		j = i
		if primeNumbers[j]:
			while j * i <= N:
				primeNumbers[j * i] = False
				j += 1
		i += 1
	return primeNumbers

def getPrime(N):
	primes = sieve(N)
	result = []
	for i in range(len(primes)):
		if primes[i]:
			result.append(i)
	return result

def factor(N):
	factors = []
	i = 1
	while i * i <= N:
		if N % i == 0:
			factors.append(i)
			if i != N // i:
				factors.append(N // i)
		i += 1
	return sorted(factors)

def gcd(a, b):
	if a < b:
		return gcd(b, a)
	if b == 0:
		return a
	return gcd(b, a % b)

def extendedGcd(a, b):
	if a < b:
		return extendedGcd(b, a)
	if b == 0:
		return [a, 1, 0]
	res = extendedGcd(b, a % b)
	x = res[2]
	y = res[1] - math.floor(a / b) * res[2]
	res[1] = x
	res[2] = y
	return res

def iterativeModularFunc(a, b, c):
	res = 1
	while b > 0:
		if b & 1:
			res = res * a % c
		a = a * a % c
		b = b // 2
	return res

def get_ints_in_variables():
	return map(int, sys.stdin.readline().strip().split())

def get_int():
	return int(input())

def get_ints_in_list():
	return list(map(int, sys.stdin.readline().strip().split()))

def get_list_of_list(n):
	return [list(map(int, sys.stdin.readline().strip().split())) for _ in range(n)]

def get_string():
	return sys.stdin.readline().strip()

def Solution(a, b, c, n, m):
	g = [[] for _ in range(n + 1)]
	for i in range(n):
		if a[i] != b[i]:
			g[b[i]].append(i)
	last = -1
	if len(g[c[-1]]) > 0:
		last = g[c[-1]][-1]
		g[c[-1]].pop()
	else:
		for i in range(n):
			if b[i] == c[-1]:
				last = i
				break
	if last == -1:
		print('NO')
		return
	ans = [0 for _ in range(m + 1)]
	ans[m - 1] = last
	for i in range(m - 1):
		if len(g[c[i]]) == 0:
			ans[i] = last
		else:
			ans[i] = g[c[i]][-1]
			g[c[i]].pop()
	for i in range(1, n + 1):
		if len(g[i]) > 0:
			print('NO')
			return
	print('YES')
	for i in range(m):
		print(ans[i] + 1, end=' ')
	print()

def main():
	for _ in range(get_int()):
		(n, m) = get_ints_in_variables()
		a = get_ints_in_list()
		b = get_ints_in_list()
		c = get_ints_in_list()
		Solution(a, b, c, n, m)
main()


import sys
import math
import bisect
from sys import stdin, stdout
from math import gcd, floor, sqrt, log
from collections import defaultdict as dd
from bisect import bisect_left as bl, bisect_right as br
from collections import Counter
from collections import defaultdict as dd
from collections import deque
flush = lambda : stdout.flush()
stdstr = lambda : stdin.readline()
stdint = lambda : int(stdin.readline())
stdpr = lambda x: stdout.write(str(x))
stdmap = lambda : map(int, stdstr().split())
stdarr = lambda : list(map(int, stdstr().split()))
mod = 1000000007
for _ in range(stdint()):
	(n, m) = stdmap()
	a = stdarr()
	b = stdarr()
	c = stdarr()
	want = dd(deque)
	matched = dd(deque)
	for i in range(n):
		if a[i] != b[i]:
			want[b[i]].append(i)
		else:
			matched[b[i]].append(i)
	res = [-1] * m
	stack = []
	for i in range(m):
		if len(want[c[i]]) == 0:
			if len(matched[c[i]]) == 0:
				stack.append(i)
			else:
				x = matched[c[i]][-1]
				res[i] = x + 1
				while stack:
					xx = stack.pop()
					res[xx] = x + 1
		else:
			x = want[c[i]].pop()
			matched[c[i]].append(x)
			res[i] = x + 1
			while stack:
				xx = stack.pop()
				res[xx] = x + 1
	pos = True
	for i in want:
		if len(want[i]) > 0:
			pos = False
			break
	if len(stack) == 0 and -1 not in res and pos:
		print('YES')
		print(*res)
	else:
		print('NO')


import sys
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	now = list(map(int, input().split()))
	goal = list(map(int, input().split()))
	color = list(map(int, input().split()))
	same = {}
	dif = {}
	for i in range(n):
		if now[i] != goal[i]:
			if goal[i] not in dif:
				dif[goal[i]] = [i]
			else:
				dif[goal[i]].append(i)
		elif now[i] not in same:
			same[now[i]] = i
	ans = []
	count = 0
	for paint in color:
		if paint in dif:
			k = dif[paint].pop()
			if len(dif[paint]) == 0:
				dif.pop(paint)
			now[k] = paint
			if paint not in same:
				same[paint] = k
			for _ in range(count + 1):
				ans.append(k + 1)
			count = 0
		elif paint in same:
			for _ in range(count + 1):
				ans.append(same[paint] + 1)
			count = 0
		else:
			count += 1
	count += len(dif)
	if count:
		print('NO')
	else:
		print('YES')
		ans = map(str, ans)
		print(' '.join(ans))


import sys
input = lambda : sys.stdin.readline().rstrip()
T = int(input())
for _ in range(T):
	(N, M) = map(int, input().split())
	A = [int(a) - 1 for a in input().split()]
	B = [int(a) - 1 for a in input().split()]
	C = [int(a) - 1 for a in input().split()][::-1]
	X = [[] for _ in range(N)]
	ANS = []
	for i in range(N):
		if A[i] != B[i]:
			X[B[i]].append(i)
	if C[0] not in B:
		print('NO')
		continue
	z = X[C[0]][-1] if X[C[0]] else B.index(C[0])
	for c in C:
		if len(X[c]) == 0:
			ANS.append(z + 1)
		else:
			ANS.append(X[c].pop() + 1)
	for x in X:
		if x:
			print('NO')
			break
	else:
		print('YES')
		print(*ANS[::-1])


from sys import stdin
t = int(stdin.readline())
for _ in range(t):
	(n, m) = map(int, stdin.readline().split())
	arra = list(map(int, stdin.readline().split()))
	arrb = list(map(int, stdin.readline().split()))
	arrc = list(map(int, stdin.readline().split()))
	dif = {}
	so = 0
	for i in range(n):
		if arra[i] != arrb[i]:
			so += 1
			if arrb[i] not in dif:
				dif[arrb[i]] = [i]
			else:
				dif[arrb[i]].append(i)
	ans = []
	if arrc[-1] not in arrb:
		print('no')
		continue
	if arrc[-1] in dif:
		cuoi = dif[arrc[-1]].pop() + 1
		so -= 1
	else:
		cuoi = arrb.index(arrc[-1]) + 1
	for i in arrc[:-1]:
		if i not in dif:
			ans.append(cuoi)
		elif len(dif[i]) > 0:
			ans.append(dif[i].pop(0) + 1)
			so -= 1
		else:
			ans.append(cuoi)
	ans.append(cuoi)
	if so > 0:
		print('no')
	else:
		print('yes')
		print(*ans)


import operator
import sys
inf = sys.stdin
input = inf.readline

def read_one_int():
	return int(input().rstrip('\n'))

def read_list_of_ints():
	res = [int(val) for val in input().rstrip('\n').split(' ')]
	return res

def read_str():
	return input().rstrip()

def check_seq(n, m, a, b, c):
	repaint_col_num = {}
	for i in range(n):
		if a[i] != b[i]:
			if b[i] not in repaint_col_num:
				repaint_col_num[b[i]] = [i + 1]
			else:
				repaint_col_num[b[i]].append(i + 1)
	colours_cnt = {}
	for col in c:
		if not col in colours_cnt:
			colours_cnt[col] = 0
		colours_cnt[col] += 1
	for (col, numbers) in repaint_col_num.items():
		if col not in colours_cnt:
			print('NO')
			return
		elif len(numbers) > colours_cnt[col]:
			print('NO')
			return
	save_col_num_1 = None
	save_col_num_2 = None
	if c[-1] in b:
		for (i, col) in enumerate(b):
			if col == c[-1]:
				if col in repaint_col_num and (not save_col_num_1):
					save_col_num_1 = repaint_col_num[col][0]
				elif not save_col_num_2:
					save_col_num_2 = i + 1
			if save_col_num_1 and save_col_num_2:
				break
	else:
		print('NO')
		return
	res = []
	if save_col_num_1:
		save_col_num = save_col_num_1
	else:
		save_col_num = save_col_num_2
	for i in range(len(c) - 1):
		if c[i] in repaint_col_num:
			cur_col_num = repaint_col_num[c[i]].pop()
			res.append(cur_col_num)
			if not repaint_col_num[c[i]]:
				del repaint_col_num[c[i]]
		else:
			res.append(save_col_num)
	res.append(save_col_num)
	print('YES')
	print(' '.join((str(i) for i in res)))

def main():
	samples = read_one_int()
	for _ in range(samples):
		(n, m) = read_list_of_ints()
		a = read_list_of_ints()
		b = read_list_of_ints()
		c = read_list_of_ints()
		check_seq(n, m, a, b, c)
main()


q = int(input())
while q:
	q -= 1
	f = 1
	ri = -1
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	c = list(map(int, input().split()))
	c.reverse()
	cntt = 0
	cnt = [[] for i in range(n)]
	res = []
	cnt2 = [[] for i in range(n)]
	for i in range(n):
		if a[i] != b[i]:
			cnt[b[i] - 1].append(i)
			ri = i
			cntt += 1
		cnt2[b[i] - 1].append(i)
	if ri == -1:
		if len(cnt2[c[0] - 1]) == 0:
			print('NO')
			continue
		else:
			print('YES')
			for i in range(m):
				print(cnt2[c[0] - 1][-1] + 1, end=' ')
			print()
			continue
	k = 0
	for i in range(m):
		j = c[i]
		if len(cnt[j - 1]):
			res.append(cnt[j - 1].pop() + 1)
			cntt -= 1
			k = 1
			ri = res[-1] - 1
		elif len(cnt2[j - 1]):
			res.append(cnt2[j - 1][-1] + 1)
			k = 1
			ri = res[-1] - 1
		elif k == 0:
			f = 0
			break
		else:
			res.append(ri + 1)
	if f and cntt == 0 and (len(res) == m):
		print('YES')
		res.reverse()
		for i in res:
			print(i, end=' ')
		print()
	else:
		print('NO')


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	c = list(map(int, input().split()))
	d = {}
	r = {}
	for i in range(len(b)):
		if a[i] == b[i]:
			r[b[i]] = i
		elif b[i] in d:
			d[b[i]].append(i)
		else:
			d[b[i]] = [i]
	e = 0
	if c[-1] not in d and c[-1] not in r:
		sys.stdout.write('NO\n')
		continue
	else:
		if c[-1] in r:
			e = r[c[-1]]
		if c[-1] in d:
			e = d[c[-1]][0]
	ans = [0] * k
	for i in range(len(c)):
		x = c[i]
		if x not in d:
			ans[i] = e + 1
		elif len(d[x]) == 0:
			ans[i] = e + 1
		else:
			ans[i] = d[x].pop() + 1
	f = 1
	for i in d:
		if len(d[i]) != 0:
			f = 0
			break
	if f:
		sys.stdout.write('YES\n')
		print(*ans)
	else:
		sys.stdout.write('NO\n')


from collections import defaultdict as dd
for _ in range(int(input())):
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	c = list(map(int, input().split()))
	y = dd(list)
	x = dd(list)
	for i in range(n):
		if b[i] == a[i]:
			x[b[i]].append(i + 1)
		else:
			y[b[i]].append(i + 1)
	ans = 0
	s = []
	for i in c:
		if y[i] != []:
			a = y[i].pop()
			x[i].append(a)
			if ans > 0:
				for j in range(ans):
					s.append(a)
				ans = 0
			s.append(a)
		elif x[i] != []:
			if ans > 0:
				for j in range(ans):
					s.append(x[i][-1])
				ans = 0
			s.append(x[i][-1])
		else:
			ans += 1
	if ans > 0:
		print('NO')
	else:
		for i in y:
			if y[i]:
				print('NO')
				break
		else:
			print('YES')
			print(*s)


from collections import defaultdict

def main():
	cases = int(input())
	ans_list = []
	for _ in range(cases):
		(n, m) = map(int, input().split(' '))
		a = list(map(int, input().split(' ')))
		b = list(map(int, input().split(' ')))
		c = list(map(int, input().split(' ')))
		fail_stack = []
		mismatches = defaultdict(list)
		mismatch_count = 0
		desired = {}
		for i in range(n):
			if a[i] != b[i]:
				mismatch_count += 1
				mismatches[b[i]].append(i)
			desired[b[i]] = i
		cur_ans = [-1 for i in range(m)]
		for (i, color) in enumerate(c):
			if mismatches[color]:
				mismatch_count -= 1
				cur_ans[i] = mismatches[color].pop() + 1
				while fail_stack:
					cur_ans[fail_stack.pop()] = cur_ans[i]
			elif color in desired:
				cur_ans[i] = desired[color] + 1
				while fail_stack:
					cur_ans[fail_stack.pop()] = cur_ans[i]
			else:
				fail_stack.append(i)
		if fail_stack or mismatch_count:
			ans_list.append('NO')
		else:
			ans_list.append('YES')
			ans_list.append(' '.join(map(str, cur_ans)))
	print('\n'.join(ans_list))
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


import sys
t = int(input())
while t > 0:
	(n, m) = map(int, input().split())
	a1 = [[] for i in range(0, n + 1)]
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	c = list(map(int, input().split()))
	for i in range(0, n):
		if b[i] != a[i]:
			a1[b[i]].append(i)
	special_color = c[m - 1]
	if len(a1[special_color]) == 0:
		for i in range(0, n):
			if b[i] == special_color:
				a1[special_color].append(i)
				break
	if len(a1[special_color]) == 0:
		print('NO')
	else:
		ans = list()
		for i in range(0, m):
			if len(a1[c[i]]) != 0:
				ans.append(a1[c[i]][0] + 1)
				if c[i] != special_color or len(a1[special_color]) > 1 or i == m - 1:
					a1[c[i]].remove(a1[c[i]][0])
			else:
				ans.append(a1[special_color][0] + 1)
		check = 0
		for i in range(0, n + 1):
			if len(a1[i]) != 0:
				check = 1
				break
		if check == 1:
			print('NO')
		else:
			print('YES')
			for i in ans:
				print(i, end=' ')
			print('')
	t -= 1


t = int(input())
for _ in range(t):

	def main():
		(n, m) = map(int, input().split())
		a = [0] + list(map(int, input().split()))
		b = [0] + list(map(int, input().split()))
		c = list(map(int, input().split()))
		need = [[] for _ in range(n + 1)]
		for i in range(1, n + 1):
			if a[i] != b[i]:
				need[b[i]].append(i)
		if not need[c[-1]]:
			for i in range(1, n + 1):
				if b[i] == c[-1]:
					need[b[i]].append(i)
					break
			else:
				return print('NO')
		ans = [need[c[-1]][-1]] * m
		for j in range(m - 1, -1, -1):
			if need[c[j]]:
				ans[j] = need[c[j]].pop()
		for i in need:
			if i:
				return print('NO')
		print('YES')
		print(' '.join(map(str, ans)))
	main()


import sys, os, io
from collections import defaultdict
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
for _ in range(int(input())):
	(n, m) = [int(i) for i in input().split()]
	a = [int(i) for i in input().split()]
	b = [int(i) for i in input().split()]
	c = [int(i) for i in input().split()]
	dic = defaultdict(lambda : [])
	for i in range(m):
		dic[c[i]].append(i)
	ans = [-1] * m
	flag = 0
	for i in range(n - 1, -1, -1):
		if a[i] != b[i]:
			if len(dic[b[i]]) > 0:
				curr = dic[b[i]].pop()
				ans[curr] = i
			else:
				flag = 1
				break
	if flag == 1:
		print('NO')
		continue
	dicb = defaultdict(lambda : -1)
	for i in range(n):
		dicb[b[i]] = i
	for i in range(m - 1, -1, -1):
		if ans[i] == -1:
			if dicb[c[i]] != -1:
				ans[i] = dicb[c[i]]
	nxt = -1
	for i in range(m - 1, -1, -1):
		if ans[i] == -1:
			if nxt == -1:
				flag = 1
				break
			else:
				ans[i] = nxt
		elif nxt == -1:
			nxt = ans[i]
	if -1 in ans:
		print('NO')
	else:
		print('YES')
		for i in range(m):
			ans[i] += 1
		print(*ans)


t = int(input())
for _ in range(t):
	(n, m) = list(map(int, input().split()))
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	finded = {}
	d = {}
	z = {}
	for i in range(n):
		if b[i] != a[i]:
			if not b[i] in d:
				d[b[i]] = 1
				z[b[i]] = [i + 1]
			else:
				d[b[i]] += 1
				z[b[i]].append(i + 1)
		else:
			finded[b[i]] = i + 1
	m = list(map(int, input().split()))
	c = [0 for i in range(len(m))]
	is_finished = False
	is_can = True
	for (ind, el) in enumerate(reversed(m)):
		if el in d:
			d[el] -= 1
			c[len(m) - 1 - ind] = z[el][0]
			if not is_finished:
				is_finished = True
				finish_ind = z[el][0]
			if len(z[el]) > 1:
				z[el].pop(0)
		else:
			if el in finded:
				c[len(m) - 1 - ind] = finded[el]
				if not is_finished:
					is_finished = True
					finish_ind = finded[el]
				continue
			if not is_finished:
				is_can = False
				break
			c[len(m) - 1 - ind] = finish_ind
	for el in d:
		if d[el] > 0:
			is_can = False
			break
	if is_can:
		print('YES')
		print(' '.join(list(map(str, c))))
	else:
		print('NO')


from pprint import pprint
import sys
input = sys.stdin.readline
import collections

def do():
	(n, m) = map(int, input().split())
	dat1 = list(map(int, input().split()))
	dat2 = list(map(int, input().split()))
	dat3 = list(map(int, input().split()))
	okpaint = collections.defaultdict(list)
	willpaint = collections.defaultdict(list)
	for i in range(n):
		if dat1[i] == dat2[i]:
			okpaint[dat1[i]].append(i)
			continue
		willpaint[dat2[i]].append(i)
	res = []
	last = -1
	lastind = -1
	for i in range(m):
		x = dat3[i]
		if len(willpaint[x]) == 0:
			if len(okpaint[x]) != 0:
				res.append(okpaint[x][0])
				last = okpaint[x][0]
				lastind = i
				continue
			else:
				res.append(None)
				continue
		next = willpaint[x].pop()
		res.append(next)
		last = next
		lastind = i
		okpaint[x].append(next)
	for i in range(m):
		if res[i] == None:
			if lastind > i:
				res[i] = last
			else:
				print('NO')
				return
	for k in willpaint.keys():
		if len(willpaint[k]) != 0:
			print('NO')
			return
	print('YES')
	print(' '.join(list(map(lambda x: str(x + 1), res))))
q = int(input())
for _ in range(q):
	do()


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	initial = list(map(int, input().split()))
	final = list(map(int, input().split()))
	painters = list(map(int, input().split()))
	last = painters[-1]
	if last in final:
		x = 0
		to_be_painted = {}
		for i in range(n):
			if initial[i] != final[i]:
				if final[i] in to_be_painted:
					to_be_painted[final[i]].append(i + 1)
				else:
					to_be_painted[final[i]] = [i + 1]
				if final[i] == last:
					x = i + 1
		if x == 0:
			x = final.index(last) + 1
		ans = []
		for p in painters:
			if p in to_be_painted:
				ans.append(str(to_be_painted[p].pop(0)))
				if not to_be_painted[p]:
					del to_be_painted[p]
			else:
				ans.append(str(x))
		if not to_be_painted.keys():
			print('YES')
			print(' '.join(ans))
		else:
			print('NO')
	else:
		print('NO')


from sys import stdin, exit
from bisect import bisect_left as bl, bisect_right as br
from itertools import accumulate
input = lambda : stdin.readline()[:-1]
intput = lambda : int(input())
sinput = lambda : input().split()
intsput = lambda : map(int, sinput())

def dprint(*args, **kwargs):
	if debugging:
		print(*args, **kwargs)
debugging = 1
t = intput()
for _ in range(t):
	(n, m) = intsput()
	a = list(intsput())
	b = list(intsput())
	c = list(intsput())
	for (i, x) in enumerate(b):
		if c[-1] == x:
			break
	else:
		print('NO')
		continue
	dump = i
	indexed = {}
	for (painter, painter_color) in enumerate(c):
		if painter_color not in indexed:
			indexed[painter_color] = set()
		indexed[painter_color].add(painter)
	targets = {}
	fail = False
	for i in range(len(a)):
		if a[i] != b[i]:
			req_color = b[i]
			if req_color in indexed and indexed[req_color]:
				painter = next(iter(indexed[req_color]))
				indexed[req_color].remove(painter)
				targets[painter] = i
			else:
				fail = True
				break
	if fail:
		print('NO')
	else:
		if m - 1 in targets:
			dump = targets[m - 1]
		print('YES')
		ans = []
		for painter in range(m):
			if painter == m - 1:
				ans.append(dump + 1)
				continue
			if painter in targets:
				ans.append(targets[painter] + 1)
			else:
				ans.append(dump + 1)
		print(' '.join(map(str, ans)))


import os, io
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
import operator
from collections import defaultdict
for _ in range(int(input())):
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	c = list(map(int, input().split()))
	d = defaultdict(list)
	e = defaultdict(list)
	for i in range(n):
		if not a[i] == b[i]:
			d[b[i]].append(i + 1)
	for i in range(m):
		e[c[i]].append(i + 1)
	if not c[-1] in b:
		print('NO')
		continue
	flag = False
	for key in d:
		if not key in e:
			flag = True
			print('NO')
			break
		if len(d[key]) > len(e[key]):
			flag = True
			print('NO')
			break
	if flag:
		continue
	print('YES')
	if c[-1] in d:
		idx = d[c[-1]][-1]
	else:
		idx = n - operator.indexOf(reversed(b), c[-1])
	f = [idx] * (m + 1)
	for key in d:
		for j in range(len(d[key])):
			f[e[key][j]] = d[key][j]
	print(*f[1:])


from collections import defaultdict

def helper():
	toDo = defaultdict(list)
	toNotDo = {}
	changes = 0
	for i in range(n):
		if a[i] != b[i]:
			toDo[b[i]].append(i)
			changes += 1
		else:
			toNotDo[b[i]] = i
	if changes > m:
		return (False, [])
	else:
		ans = []
		lastChange = -1
		for i in range(m):
			if toDo[willPaint[i]]:
				ind = toDo[willPaint[i]].pop()
				toNotDo[willPaint[i]] = ind
				ans.append(ind + 1)
				changes -= 1
				lastChange = i
			elif willPaint[i] in toNotDo:
				ans.append(toNotDo[willPaint[i]] + 1)
				lastChange = i
			else:
				ans.append(0)
		if changes == 0:
			for i in range(m):
				if ans[i] == 0:
					if lastChange > i:
						ans[i] = ans[lastChange]
					else:
						return (False, [])
			return (True, ans)
		else:
			return (False, [])
for _ in range(int(input())):
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	willPaint = list(map(int, input().split()))
	(ans, arr) = helper()
	if ans:
		print('YES')
		print(*arr)
	else:
		print('NO')


import io, os
from collections import deque
dev = 0
if dev:

	def read():
		return input().strip()
else:
	input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline

	def read():
		return input().decode()
t = int(read())

def solve():
	(n, m) = map(int, read().split())
	initial = list(map(int, read().split()))
	desired = list(map(int, read().split()))
	painters = list(map(int, read().split()))
	set_desired = set(desired)
	dict_colors = dict()
	dict_painters = dict()
	res = deque()
	for (i, (ini, des)) in enumerate(zip(initial, desired)):
		if ini != des:
			try:
				dict_colors[des][0] += 1
				dict_colors[des][1].append(i)
			except:
				dict_colors[des] = [1, deque([i])]
	for painter in painters:
		dict_painters[painter] = dict_painters.get(painter, 0) + 1
	for key in dict_colors.keys():
		if dict_colors[key][0] > dict_painters.get(key, 0):
			return False
	trash = -1
	if painters[-1] in set_desired:
		if dict_colors.get(painters[-1], 0):
			trash = dict_colors[painters[-1]][1][0]
			dict_colors[painters[-1]][1].popleft()
			dict_colors[painters[-1]][0] -= 1
			if dict_colors[painters[-1]][0] == 0:
				dict_colors.pop(painters[-1])
		else:
			trash = desired.index(painters[-1])
	else:
		return False
	for painter in painters:
		if dict_colors.get(painter, 0):
			res.append(dict_colors[painter][1][0])
			dict_colors[painter][1].popleft()
			dict_colors[painter][0] -= 1
			if dict_colors[painter][0] == 0:
				dict_colors.pop(painter)
		else:
			res.append(trash)
	return res
while t:
	s = solve()
	if s:
		print('YES')
		print(''.join([str(x + 1) + ' ' for x in s]))
	else:
		print('NO')
	t -= 1


import os
import sys
import math
from io import BytesIO, IOBase
from fractions import Fraction
import collections
from itertools import permutations
from collections import defaultdict
from collections import deque
import threading
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

class SegmentTree:

	def __init__(self, data, default=-10 ** 6, func=lambda a, b: max(a, b)):
		self._default = default
		self._func = func
		self._len = len(data)
		self._size = _size = 1 << (self._len - 1).bit_length()
		self.data = [default] * (2 * _size)
		self.data[_size:_size + self._len] = data
		for i in reversed(range(_size)):
			self.data[i] = func(self.data[i + i], self.data[i + i + 1])

	def __delitem__(self, idx):
		self[idx] = self._default

	def __getitem__(self, idx):
		return self.data[idx + self._size]

	def __setitem__(self, idx, value):
		idx += self._size
		self.data[idx] = value
		idx >>= 1
		while idx:
			self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
			idx >>= 1

	def __len__(self):
		return self._len

	def query(self, start, stop):
		if start == stop:
			return self.__getitem__(start)
		stop += 1
		start += self._size
		stop += self._size
		res = self._default
		while start < stop:
			if start & 1:
				res = self._func(res, self.data[start])
				start += 1
			if stop & 1:
				stop -= 1
				res = self._func(res, self.data[stop])
			start >>= 1
			stop >>= 1
		return res

	def __repr__(self):
		return 'SegmentTree({0})'.format(self.data)

class SegmentTree1:

	def __init__(self, data, default=10 ** 6, func=lambda a, b: min(a, b)):
		self._default = default
		self._func = func
		self._len = len(data)
		self._size = _size = 1 << (self._len - 1).bit_length()
		self.data = [default] * (2 * _size)
		self.data[_size:_size + self._len] = data
		for i in reversed(range(_size)):
			self.data[i] = func(self.data[i + i], self.data[i + i + 1])

	def __delitem__(self, idx):
		self[idx] = self._default

	def __getitem__(self, idx):
		return self.data[idx + self._size]

	def __setitem__(self, idx, value):
		idx += self._size
		self.data[idx] = value
		idx >>= 1
		while idx:
			self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
			idx >>= 1

	def __len__(self):
		return self._len

	def query(self, start, stop):
		if start == stop:
			return self.__getitem__(start)
		stop += 1
		start += self._size
		stop += self._size
		res = self._default
		while start < stop:
			if start & 1:
				res = self._func(res, self.data[start])
				start += 1
			if stop & 1:
				stop -= 1
				res = self._func(res, self.data[stop])
			start >>= 1
			stop >>= 1
		return res

	def __repr__(self):
		return 'SegmentTree({0})'.format(self.data)
MOD = 10 ** 9 + 7

class Factorial:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorials = [1, 1]
		self.invModulos = [0, 1]
		self.invFactorial_ = [1, 1]

	def calc(self, n):
		if n <= -1:
			print('Invalid argument to calculate n!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.factorials):
			return self.factorials[n]
		nextArr = [0] * (n + 1 - len(self.factorials))
		initialI = len(self.factorials)
		prev = self.factorials[-1]
		m = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * i % m
		self.factorials += nextArr
		return self.factorials[n]

	def inv(self, n):
		if n <= -1:
			print('Invalid argument to calculate n^(-1)')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		p = self.MOD
		pi = n % p
		if pi < len(self.invModulos):
			return self.invModulos[pi]
		nextArr = [0] * (n + 1 - len(self.invModulos))
		initialI = len(self.invModulos)
		for i in range(initialI, min(p, n + 1)):
			next = -self.invModulos[p % i] * (p // i) % p
			self.invModulos.append(next)
		return self.invModulos[pi]

	def invFactorial(self, n):
		if n <= -1:
			print('Invalid argument to calculate (n^(-1))!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.invFactorial_):
			return self.invFactorial_[n]
		self.inv(n)
		nextArr = [0] * (n + 1 - len(self.invFactorial_))
		initialI = len(self.invFactorial_)
		prev = self.invFactorial_[-1]
		p = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * self.invModulos[i % p] % p
		self.invFactorial_ += nextArr
		return self.invFactorial_[n]

class Combination:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorial = Factorial(MOD)

	def ncr(self, n, k):
		if k < 0 or n < k:
			return 0
		k = min(k, n - k)
		f = self.factorial
		return f.calc(n) * f.invFactorial(max(n - k, k)) * f.invFactorial(min(k, n - k)) % self.MOD
mod = 10 ** 9 + 7
omod = 998244353
prime = [True for i in range(50001)]
pp = []

def SieveOfEratosthenes(n=50000):
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	for i in range(50001):
		if prime[i]:
			pp.append(i)
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	c = list(map(int, input().split()))
	count = defaultdict(list)
	d = defaultdict(int)
	ch = 1
	ex = [0] * (n + 1)
	s = set(b)
	for i in range(n):
		if a[i] != b[i]:
			d[b[i]] += 1
			count[b[i]].append(i + 1)
		ex[b[i]] = i + 1
	res = []
	for i in range(k - 1, -1, -1):
		if d[c[i]] > 0:
			d[c[i]] -= 1
			res.append(count[c[i]].pop())
		elif c[i] in s:
			res.append(ex[c[i]])
		else:
			if len(res) == 0:
				ch = 0
				break
			res.append(res[-1])
	for i in d:
		if d[i] != 0:
			ch = 0
			break
	if ch == 0:
		print('NO')
	else:
		res = res[::-1]
		print('YES')
		print(*res)


from sys import stdin as cin
from itertools import groupby
from collections import deque
lmap = lambda f, v: list(map(f, v))

def apply_paint(a, c, d):
	a = a.copy()
	for (col, bar) in zip(c, d):
		a[bar] = col
	return a

def find_painting(a, b, c):
	if c[-1] not in b:
		return
	paint_order_tuples = sorted(((b[i], a[i] == b[i], i) for i in range(len(b))))
	paint_order = {k: deque(map(lambda x: x[2], g)) for (k, g) in groupby(paint_order_tuples, lambda x: x[0])}
	prev_bar = -1
	d = []
	for col in reversed(c):
		paint_bars = paint_order.get(col)
		if paint_bars:
			last_bar = paint_bars.popleft()
			d.append(last_bar)
			paint_bars.append(last_bar)
		else:
			d.append(last_bar)
	d.reverse()
	a1 = apply_paint(a, c, d)
	return lmap(lambda x: x + 1, d) if a1 == b else None

def main():
	t = int(next(cin).strip())
	for i in range(t):
		next(cin)
		a = lmap(int, next(cin).strip().split())
		b = lmap(int, next(cin).strip().split())
		c = lmap(int, next(cin).strip().split())
		paint = find_painting(a, b, c)
		print('YES' if paint else 'NO')
		if paint:
			print(' '.join(map(str, paint)))
main()


import sys
from collections import defaultdict

def solve(n, m, a, b, c):
	free = -1
	last = -1
	for i in range(n):
		if b[i] == c[-1]:
			last = i + 1
			if b[i] != a[i]:
				free = i + 1
	if last == -1:
		print('NO')
		return
	if free == -1:
		free = last
	q = defaultdict(list)
	for i in range(n):
		if a[i] != b[i] and i + 1 != free:
			q[b[i]].append(i + 1)
	ans = []
	for i in range(m - 1):
		if q[c[i]]:
			ans.append(q[c[i]].pop())
		else:
			ans.append(free)
	for x in q:
		if q[x]:
			print('NO')
			return
	ans.append(free)
	print('YES')
	print(*ans)
	return
for nt in range(int(input())):
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	c = list(map(int, input().split()))
	solve(n, m, a, b, c)


def main():
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	c = list(map(int, input().split()))
	q = [[] for _ in range(n + 1)]
	idx = [-1] * (n + 1)
	for i in range(n):
		idx[b[i]] = i + 1
		if a[i] != b[i]:
			q[b[i]].append(i + 1)
	x = [0] * m
	ok = -1
	for j in range(m - 1, -1, -1):
		if q[c[j]]:
			x[j] = q[c[j]].pop()
			ok = x[j]
		elif ok != -1:
			x[j] = ok
		elif idx[c[j]] != -1:
			x[j] = idx[c[j]]
			ok = x[j]
		else:
			print('NO')
			return
	for i in range(n + 1):
		if q[i]:
			print('NO')
			return
	print('YES')
	print(*x)
	return
t = int(input())
for i in range(t):
	main()


from collections import defaultdict
import sys
input = sys.stdin.readline
for _ in range(int(input())):
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	c = list(map(int, input().split()))
	needs = [list() for i in range(n + 1)]
	wants = [list() for i in range(n + 1)]
	for i in range(n):
		wants[b[i]].append(i + 1)
		if a[i] != b[i]:
			needs[b[i]].append(i + 1)
	ans = True if wants[c[-1]] else False
	res = [-1] * m
	for i in range(m - 1, -1, -1):
		if needs[c[i]]:
			res[i] = needs[c[i]].pop()
		elif wants[c[i]]:
			res[i] = wants[c[i]][-1]
		else:
			res[i] = res[-1]
	for i in range(n + 1):
		if needs[i]:
			ans = False
			break
	if ans:
		print('YES')
		print(*res)
	else:
		print('NO')


from os import path
from io import BytesIO, IOBase
import sys
from heapq import heappush, heappop
from functools import cmp_to_key as ctk
from collections import deque, Counter, defaultdict as dd
from bisect import bisect, bisect_left, bisect_right, insort, insort_left, insort_right
from itertools import permutations
from datetime import datetime
from math import ceil, sqrt, log, gcd

def ii():
	return int(input())

def si():
	return input().rstrip()

def mi():
	return map(int, input().split())

def li():
	return list(mi())
abc = 'abcdefghijklmnopqrstuvwxyz'
mod = 1000000007
inf = float('inf')
vow = ['a', 'e', 'i', 'o', 'u']
(dx, dy) = ([-1, 1, 0, 0], [0, 0, 1, -1])

def bo(i):
	return ord(i) - ord('0')
file = 1

def ceil(a, b):
	return (a + b - 1) // b

def solve():
	for _ in range(ii()):
		(n, m) = mi()
		a = li()
		b = li()
		c = li()
		f = [0] * (n + 1)
		need = [[] for i in range(n + 1)]
		for i in range(n):
			if a[i] != b[i]:
				need[b[i]].append(i + 1)
			f[b[i]] = i + 1
		ok = True
		ans = [0] * m
		for i in range(m):
			if f[c[i]] == 0:
				if len(need[c[-1]]) == 0:
					ans[i] = f[c[-1]]
					continue
				ans[i] = need[c[-1]][0]
			elif len(need[c[i]]) > 0:
				ans[i] = need[c[i]][-1]
				need[c[i]].pop()
			else:
				if len(need[c[-1]]) == 0:
					ans[i] = f[c[-1]]
					continue
				ans[i] = need[c[-1]][0]
		for i in range(m):
			a[ans[i] - 1] = c[i]
		if a == b and ok:
			print('YES')
			print(*ans)
		else:
			print('NO')
if file:
	if path.exists('input.txt'):
		sys.stdin = open('input.txt', 'r')
		sys.stdout = open('output.txt', 'w')
	else:
		input = sys.stdin.readline
solve()


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	c = list(map(int, input().split()))
	d1 = {}
	for i in range(n):
		if a[i] in d1:
			d1[a[i]].append(i)
		else:
			d1[a[i]] = [i]
	if a == b:
		ans = []
		for i in range(m):
			if c[i] in d1:
				val = d1[c[i]][0] + 1
				ans.append(val)
			else:
				ans.append(-1)
		if set(ans) == {-1} or ans[-1] == -1:
			print('NO')
		else:
			print('YES')
			for i in range(m):
				if ans[i] == -1:
					print(val, end=' ')
				else:
					print(ans[i], end=' ')
			print()
	else:
		(p, q) = ([], [])
		for i in range(n):
			if a[i] != b[i]:
				p.append(a[i])
				q.append(b[i])
			else:
				p.append(-1)
				q.append(-1)
		d2 = {}
		for i in range(n):
			if q[i] in d2:
				d2[q[i]].append(i)
			else:
				d2[q[i]] = [i]
		ans = []
		for i in range(m):
			if c[i] in d2:
				val = d2[c[i]][0] + 1
				ans.append(val)
				if len(d2[c[i]]) == 1:
					del d2[c[i]]
				else:
					d2[c[i]].pop(0)
				if len(d1[a[val - 1]]) == 1:
					del d1[a[val - 1]]
				else:
					d1[a[val - 1]].remove(val - 1)
				if c[i] in d1:
					d1[c[i]].append(val - 1)
				else:
					d1[c[i]] = [val - 1]
				a[val - 1] = c[i]
			elif c[i] in d1:
				val = d1[c[i]][0] + 1
				ans.append(val)
			else:
				ans.append(-1)
		if set(ans) == {-1} or a != b or ans[-1] == -1:
			print('NO')
		else:
			print('YES')
			for i in range(m):
				if ans[i] == -1:
					print(val, end=' ')
				else:
					print(ans[i], end=' ')
			print()


import bisect
import collections
import copy
import functools
import heapq
import itertools
import math
import random
import re
import sys
import time
import string
from typing import List
sys.setrecursionlimit(999999)
for _ in range(int(input())):
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	c = list(map(int, input().split()))
	chg = collections.defaultdict(list)
	unchg = collections.defaultdict(list)
	uf = []
	zh = -1
	for i in range(n):
		if a[i] == b[i]:
			chg[b[i]].append(i + 1)
		else:
			unchg[b[i]].append(i + 1)
	ans = [-1] * m
	for (i, cc) in enumerate(c):
		if unchg[cc]:
			kc = unchg[cc].pop()
			ans[i] = kc
			chg[cc].append(kc)
			zh = kc
		elif chg[cc]:
			ans[i] = chg[cc][0]
			zh = ans[i]
		else:
			uf.append(i)
			zh = -1
	for v in unchg.values():
		if v:
			print('NO')
			break
	else:
		if zh == -1 and uf:
			print('NO')
		else:
			if uf:
				for i in uf:
					ans[i] = zh
			print('YES')
			print(*ans)


T = int(input())
for _ in range(T):
	(n, m) = [int(x) for x in input().split()]
	a = [int(x) for x in input().split()]
	b = [int(x) for x in input().split()]
	c = [int(x) for x in input().split()]
	needed = [[] for _ in range(n)]
	cols_at_end = [-1 for _ in range(n)]
	total_needed = 0
	for i in range(n):
		if a[i] != b[i]:
			needed[b[i] - 1] += [i]
			total_needed += 1
		cols_at_end[b[i] - 1] = i
	plan = []
	fail = False
	for col in reversed(c):
		if len(needed[col - 1]) > 0:
			where = needed[col - 1].pop()
			plan += [where]
			total_needed -= 1
		elif cols_at_end[col - 1] != -1:
			plan += [cols_at_end[col - 1]]
		elif len(plan) == 0:
			fail = True
			break
		else:
			plan += [plan[-1]]
	if fail or total_needed > 0:
		print('NO')
	else:
		print('YES')
		print(' '.join([str(x + 1) for x in reversed(plan)]))