t = int(input())
for i in range(t):
    (n, m) = input().split(' ')
    n = int(n)
    m = int(m)
    arr_1 = input().split(' ')
    arr_2 = input().split(' ')
    check = 0
    for j in range(n):
        if arr_1[j] in arr_2:
            print('YES')
            print('1', arr_1[j])
            check = 1
            break
    if check == 0:
        print('NO')