import sys
max_int = 1000000001  # 10^9+1
min_int = -max_int

t = int(input())
for _t in range(t):
    m, n = map(int, sys.stdin.readline().split())
    a = set(map(int, sys.stdin.readline().split()))
    b = map(int, sys.stdin.readline().split())

    for one in b:
        if one in a:
            print('YES')
            print('1', one)
            break
    else:
        print('NO')

