t=int(input())
for _ in range(t):
    p=list(map(int,input().split()))
    n,m=p[0],p[1]
    a=list(map(int,input().split()))
    b=list(map(int,input().split()))
    key=0
    for i in a:
        for j in b:
            if(i==j):
                print("YES")
                print(1,i)
                key=1
                break
        if(key==1):
            break
    if(key==0):
        print("NO")
