def ans(a,b):
    return list(a.intersection(b))

t=int(input())
L=[]
for i in range(t):
    n,m=map(int,input().split())
    a=set([int(x) for x in input().split()])
    b=set([int(x) for x in input().split()])
    L.append(ans(a,b))

for l in L:
    if len(l)==0:
        print('NO')
    else:
        print('YES')
        print(1,l[0])
