t=int(input())
for _ in range(t):
    n,m=map(int,input().split())
    l=list(map(int,input().split()))
    g=list(map(int,input().split()))
    u=0
    if len(l)>len(g):
        for i in l:
            if i in g:
                u=i
                break
    else:
        for i in g:
            if i in l:
                u=i
                break
    if u!=0:
        print("YES")
        print(1,u)
    else:
        print("NO")