for _ in range(int(input())):
    n, m = map(int, input().split())
    a = set(list(map(int, input().split())))
    b = set(list(map(int, input().split())))
    c = a.intersection(b)
    d = [x for x in c]
    if len(c):
        print('YES')
        print(1, d[0])
    else:
        print('NO')
