def f(l1,l2):
    l=0
    arr=0
    for i in l1:
        if l==0:
            if i in l2:
                l=1
                arr=i
                return l, arr
    return 0,0
for _ in range(int(input())):
    n,m=map(int, input().split())
    l1=list(map(int, input().split()))
    l2=list(map(int, input().split()))
    l,ele=f(l1,l2)
    if l:
        print("YES")
        print(l,ele)
    else:
        print("NO")