import sys, heapq, bisect

tc = int(sys.stdin.readline())
for _ in range(tc):
    n, m = map(int, sys.stdin.readline().split())
    a = list(map(int, sys.stdin.readline().split()))
    b = list(map(int, sys.stdin.readline().split()))
    c = []
    for i in range(n):
        for j in range(m):
            if a[i] == b[j]:
                c.append(a[i])
    if not c:
        print('NO')
    else:
        print('YES')
        print(1, c[0])