t = int(input())
for i in range(t):
    n,m = map(int, input().split())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))
    t = 0
    for j in range(n):
        for k in range(m):
            if a[j] == b[k]:
                t += 1
                p = a[j]
                break
    if t == 0:
        print('NO')
    else:
        print('YES')
        print(1,p)