t=int(input())
for i in range(t):
    n,m=map(int,input().split())
    lstn=list(map(int,input().split()))
    lstm=list(map(int,input().split()))
    count={}
    flag=0
    for i in lstn:
        if i not in count:
            count[i]=1
    for j in lstm:
        if j in count:
            print('YES')
            print(1,j)
            flag=1
            break
    if(flag==0):
        print('NO') 
