import math
from sys import stdin,stdout
for _ in range(int(input())):
    n,m=map(int,input().split())
    l1=list(set(map(int,input().split())))
    l2=list(set(map(int,input().split())))
    f=0
    for i in l1:
        f=0
        if i in l2:
            print("YES")
            print(1,i)
            f=1
            break
        if f==1:
            break
    if f==0:
        print("NO")
        #print(0)
    