from collections import deque
import sys

def inp():
    return sys.stdin.readline().strip()
for _ in range(int(inp())):
    n,m=map(int,inp().split())
    a=set(sorted(map(int,inp().split())))
    b=set(sorted(map(int,inp().split())))
    s=a&b 
    s=sorted(s)
    if s:
        print('YES')
        print(1,s[0])
    else:
        print('NO')