t = int(input())
l=[]
for i in range(5):
    l.append(i)
for _ in range(t):
    n, m = map(int, input().split())
    nL = list(map(int, input().split()))
    mL = list(map(int, input().split()))
    im=0
    km=0

    flag = False
    for i in nL:
        if i in mL:
            print('YES')
            print(1, i)
            flag = True
            im+=1
            break
    if flag == False:
        print('NO')
        km+=1