# A. Common Subsequence
t=int(input())
for i in range(t):
    n,m=map(int,input().split())
    a=set(map(int,input().split()))
    b=set(map(int,input().split()))
    c=a.intersection(b)
    x=list(c)
    if len(x)==0:
        print("NO")
    else:
        print("YES")
        print(1,x[0])
