import sys
from collections import defaultdict
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

t = inp()
for _ in range(t):
    n,m = inpl()
    a = inpl()
    b = inpl()
    B = set(b)
    res = -1
    for x in a:
        if x in B:
            res = x
            break
    if res == -1:
        print('NO')
    else:
        print('YES')
        print(1,res)

    