count = int(input())
for i in range(count):
    n, m = map(int, input().split(' '))
    list_n = list(map(int, input().split(' ')))
    list_m = list(map(int, input().split(' ')))
    for j in range(n):
        if(list_n[j] in list_m):
            print('YES')
            print(1, list_n[j])
            break
    else:
        print('NO')