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()))
    c=0
    for j in range(n):
        if a[j] in b:
            c+=1
            print("YES")
            print(1,end=" ")
            print(a[j])
            break
    if c==0:
        print("NO")