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()))
		a1,b1,f=set(a),set(b),False
		for i in range(m):
			if(b[i] in a1):
				f=True
				print('YES')
				print(1,b[i])
				break
		if(not f):
			print('NO')
main()