#code
t=int(input())
for i in range(t):
    n,m=[int(x) for x in input().strip().split()]
    a=list(map(int,input().strip().split()))[:n]
    b=list(map(int,input().strip().split()))[:m]
    tyler=-1
    for i in range(n):
        if b.count(a[i])>0:
            tyler=a[i]
            break
    if tyler==-1:
        print("NO")
    else:
        print("YES")
        print(1,tyler)