def c(a,b):
    for j in range(0,len(a)):
        x = a[j]
        if a[j] in b:
            return x
            break
    return -1

t  = int(input())
for i in range(0,t):
    n,m =[int(i) for i in input().split()]
    a = [int(i) for i in input().split()]
    b = [int(i) for i in input().split()]
    x=c(a,b)
    if x!=-1:
        print("YES")
        print("1 " + str(x))
    else:
        print("NO")
