# cook your dish here
t=int(input())
for _ in range(t):
    n,m=list(map(int,input().rstrip().split()))
    a=list(map(int,input().rstrip().split()))
    b=list(map(int,input().rstrip().split()))
    da={}
    for i in range(n):
        if a[i] not in da.keys():
            da[a[i]]=True
    c=[]
    for i in range(m):
        if b[i] in da.keys():
            c.append(b[i])
            break
    if len(c)!=0:
        print('YES')
        print(1,c[0])
    else:
        print('NO')
        