cases = int(input())

for case in range(cases):
    answer = False
    n, m = [int(item) for item in input().split(' ')]
    a = [int(item) for item in input().split(' ')]
    b = [int(item) for item in input().split(' ')]
    for term in a:
        if term in b:
            answer = True
            break
    if answer:
        print('YES')
        print(1, term)
    else:
        print('NO')
