n=int(input())
for i in range(n):
    a,b=[int(i) for i in input().split()]
    c=[int(i) for i in input().split()]
    d=[int(i) for i in input().split()]
    e=0
    flag=0
    for j in range(0,len(c)):
        if(c[j] in d):
            e=c[j]
            flag=1
            break
    if(flag==0):
        print('NO')
    else:
        print('YES')
        print(1,e)