from sys import stdin
input = stdin.readline

t = int(input())

for _ in range(t):
    n, m = list(map(int, input().rstrip().split(" ")))
    a = set(map(int, input().rstrip().split(" ")))
    b = set(map(int, input().rstrip().split(" ")))

    c = a.intersection(b)
    if len(c) == 0:
        print('NO')
    else:
        print('YES')
        print(1, c.pop())