t = int(input())
for i in range(t):
    n,m = map(int,input().split())
    l = set(list(map(int,input().split())))
    y = set(list(map(int,input().split())))
    z = list(l.intersection(y))
    if(len(z)==0):
        print("NO")
    else:
        print("YES")
        print("1 "+str(z[0]))