for _ in range(int(input())):
    a,b=[int(x) for x in input().split()]
    arr1=[int(x) for x in input().split()]
    arr2=[int(x) for x in input().split()]
    flag=False
    for i in arr1:
        for j in arr2:
            if i==j:
                print("YES")
                print('1',i)
                flag=True
                break
        if flag==True:
            break
        
    if flag==False:
        print("NO")