'''Author- Akshit Monga'''
import sys
# input=sys.stdin.readline
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()]
    ans="NO"
    for i in a:
        for j in b:
            if i==j:
                ans="YES"
                pivot=i
                break
    print(ans)
    if ans=="YES":
        print(1,pivot)