import collections
t=int(input())
for q in range(0,t):
    n,m=map(int,input().split())
    a=[int(i) for i in input().split()]
    b=[int(i) for i in input().split()]
    d1=collections.Counter(a)
    d2=collections.Counter(b)
    flag="NO"
    index=-1
    for i in d1:
        if d2[i]!=0:
            flag="YES"
            index=i
    print(flag)
    if index!=-1:
        print(1,index)