t=int(input())
for test in range(t):
    n,m=[int(x) for x in input().split()]
    a1=[int(x) for x in input().split()]
    a2=[int(x) for x in input().split()]
    dict={}
    for i in a1:
        dict[i]=0

    found=0
    for j in a2:
        if j in dict:
            print('YES')
            print(1,j)
            found=1
            break
    if found==0:
        print('NO')
