for i in range(int(input())):
    n, m = map(int, input().split())
    a, b = set(map(int, input().split())), set(map(int, input().split()))
    if (len(a & b) == 0): print('NO')
    else: print('YES\n', 1,' ', list(a & b)[0], sep = '')
        