# -*- coding: utf-8 -*-
"""
Created on Wed Jul  8 16:37:05 2020

@author: Pooja Patidar
"""

for _ in range(int(input())):
    n,m=map(int,input().split())
    a=list(map(int,input().split()[:n]))
    b=list(map(int,input().split()[:m]))
    c=[]
    for i in a:
        for j in b:
            if i==j:
                c.append(i)
    if len(c)==0:
        print("NO")
    else:
        print("YES")
        print(1,min(c))
        