for _ in range(int(input())):
    n,m=map(int,input().split())
    a=list(map(int,input().split()))
    b=list(map(int,input().split()))
    c=[]
    for i in range(len(a)):
        if a[i] in b:
            c.append(a[i])
            break
    if len(c)==0:
        print("NO")
    else:
        print("YES")
        print(len(c),*c)