t = int(input())
for i in range(t):
    n,m = [int(j) for j in input().split()[:2]]

    x = [int(k) for k in input().split()[:n]]
    y = [int(l) for l in input().split()[:m]]
    f=0
    for j in range(n):
        if(x[j] in y):
            p = j
            f+=1
            break
        else:
            pass
    if(f>0):
        print('YES')
        print(1,x[p])
    else:
        print('NO')