t = int(input())
for f in range(t):
    n, m = map(int, input().split())
    n_arr = list(map(int, input().strip().split()))
    m_arr = list(map(int, input().strip().split()))
    a = -1
    for i in range(n):
        for j in range(m):
            if n_arr[i] == m_arr[j]:
                a = n_arr[i]
                break
    if a != -1:
        print('YES')
        print(1, a)
    else:
        print('NO')