# import sys

# sys.stdin = open('input.txt', 'r')
# sys.stdout = open('output.txt', 'w')

t = 1
t = int(input())

while t:
    t -= 1

    # n = int(input())
    n, m = list(map(int, input().split()))
    a= list(map(int, input().split()))
    b = list(map(int, input().split()))

    a_map = {}
    for el in a:
        a_map[el] = True
    
    for el in b:
        if el in a_map:
            print('YES')
            print(1,el)
            break
    else:
        print('NO')

    
    
