for _ in range(int(input())):
    a1,b1=map(int,input().split())
    a=list(map(int,input().split()))
    b=list(map(int,input().split()))
    c=list(set(a)&set(b))
    if len(c)!=0:
        print("YES")
        print(1,c[0])
    else:
        print("NO")