from math import *
from collections import *
from random import *
from bisect import *
import sys
input=sys.stdin.readline
t=int(input())
while(t):
    t-=1
    n,m=map(int,input().split())
    a=list(map(int,input().split()))
    b=list(map(int,input().split()))
    a=set(a)
    b=set(b)
    f=0
    for i in a:
        if(i in b):
            f=1
            pos=i
            break
    if(f):
        print("YES")
        print(1,pos)
    else:
        print("NO")
