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