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()))
    d=dict()
    for j in range(n):
        d[a[j]]=1
    c=[]
    for j in range(m):
        if b[j] in d.keys():
            c.append(b[j])
            break
    if len(c)==0:
        print("NO")
    else:
        print("YES")
        print(1, c[0])
