for t in range(int(input())):
    n,m=input().split()
    n=int(n)
    m=int(m)
    a=[]
    a=list(map(int,input().split()))
    b=[]
    b=list(map(int,input().split()))
    flag=0
    for each in a:
        if each in b:
            print("YES")
            print("1",each)
            flag=1
            break
    if flag==0:
        print("NO")
            