for x in range(int(input())):
    n,m=map(int,input().split())
    a=sorted(list(map(int,input().split())))
    b=sorted(list(map(int,input().split())))
    c=list()
    count=0
    for j in a:
        if j in b:
            count=count+1
            c.append(j)
    if(count>=1):
        print('YES')
        print('1',end=" ")
        print(c[0])
    else:
        print('NO')
