t=int(input())
for z in range(t):
    n,m=map(int,input().split())
    arr1=list(map(int,input().split()))
    arr2=list(map(int,input().split()))
    temp=-1
    for i in range(n):
        for j in range(m):
            if(arr1[i]==arr2[j]):
                temp=arr1[i]
                break
    if(temp>0):
        print("YES")
        print("1",temp)
    else:
        print("NO")
