t = int(input())
for tes in range(t):
    n,m=map(int,input().split())
    arr1 = list(map(int,input().split()))
    arr2 = list(map(int,input().split()))
    h= [0]*1001
    res = []
    f = 0
    for i in range(n):
        h[arr1[i]]+=1
    for i in range(m):
        if(h[arr2[i]]!=0):
            print("YES")
            print(1,arr2[i])
            f = 1
            break
    if(f==0):
        print("NO")
    