t=int(input())


for i in range(t):
    n,m=(int(x) for x in input().split())
    a=list(int(x) for x in input().split())
    b=list(int(x) for x in input().split())
    
    a_set=set(a)
    intersection=list(a_set.intersection(b))
    
    if (intersection!=[]):
        print('YES\n1 %s'  %(intersection[0]))
    else:
        print("NO")