x=int(input())
for i in range(0,x):
    n,m=[int(a) for a in input().split()]
    a=list(map(int,input().split()))[:n]
    b=list(map(int,input().split()))[:m]
    s=0
    for j in range(n):
        if(b.count(a[j])!=0):
            s=1
            break
    if(s):
        print("YES")
        print(1,a[j])
    else:
        print("NO")