t=int(input())
for i in range(t):
    x = input().split()
    n = int(x[0])
    m = int(x[1])
    p1,p2=[],[]
    e = input()
    for j in e.split():
        v= int(j)
        p1.append(v)
    e = input()
    for j in e.split():
        v= int(j)
        p2.append(v)
    flag=0    
    for j in p1:    
        if j in p2:
            print("YES")
            print(1,j)
            flag=1
            break
    if flag==0:
        print("NO")