for _ in range(int(input())):
    n,m=map(int,input().split())
    a=sorted(list(map(int,input().split())))
    b=sorted(list(map(int,input().split())))
    A=[]
    for i in range(n):
        if a[i] in b:
            A.append(a[i])
            break
    if len(A)>0:
        print('YES')
        print(1,*A)
    else:
        print('NO')
