for _ in range(int(input())):
    n,m=map(int,input().split())
    l=list(map(int,input().split()))
    g=list(map(int,input().split()))
    l=set(l)
    g=set(g)
    ans=l.intersection(g)
    if len(ans)==0:
        print("NO")
    else:
        actualans = ans.pop()
        print("YES")
        print("1",actualans)