#dt = {} for i in x: dt[i] = dt.get(i,0)+1
import sys;input = sys.stdin.readline
inp,ip = lambda :int(input()),lambda :[int(w) for w in input().split()]

for _ in range(inp()):
    n,m = ip()
    x = ip()
    y = ip()
    dt = {} 
    for i in x: dt[i] = dt.get(i,0)+1
    flag = 0
    ans = -1
    for i in y:
        if dt.get(i,0):
            ans = i
            flag = 1
            break
    if flag:
        print("YES")
        print(1,ans)
    else:
        print("NO")

