from bisect import bisect_left
t=int(input())
for o in range(0,t):
    n,m=map(int,input().split(" "))
    arr1=list(map(int,input().split(" ")))
    arr2=list(map(int,input().split(" ")))
    arr1.sort()
    arr2.sort()
    flag=0
    for i in range(0,n):
        res=bisect_left(arr2,arr1[i])
        if res != m and arr2[res] == arr1[i]: 
            print("YES")
            flag=1
            print("1 {}".format(arr1[i]))
            break
    if(flag==0):
        print("NO")
        