t=int(input())
while(t!=0):
    n1,n2=map(int,input().split())
    arr=[int(x) for x in input().split()]
    arr1=[int(y) for y in input().split()]
    res=0
    y_n='NO'
    for i in range(len(arr)):
        for j in range(len(arr1)):
            if arr[i] == arr1[j]:
                res=arr[i]
                y_n="YES"
    if y_n=='YES':
        print(y_n)
        print('1',res)
    else:
        print(y_n)
    t-=1