import math
from collections import defaultdict,deque
from bisect import bisect_left,bisect_right

from sys import stdin    
def mp():return map(int,stdin.readline().split())
def ml():return list(map(int,stdin.readline().split()))

for _ in range(int(input())):
    n,m=mp()
    a=ml();b=ml()
    flag=False;ans=-1
    for x in a:
        if x in b:
            flag=True
            ans=x
            break
    if flag:
        print("YES")
        print(1, x)
    else: print("NO")