The next step sorts the squared-distance rows. The table shows how k and the equal-distance tie-break select the nearest training indices.
Pick the k smallest rows
With k=3, the selected rows are the three smallest squared distances.
k=3⇒ take the smallest 3
Why the tie-break is explicit
Equal d^2 values are sorted by lowest training index. Here the nearest indices are 0, 1, and 2.
nearest indices=[0,1,2]
Summary
The nearest rows all have class A and d^2=2. The vote has not been summarized yet.
nearest classes=A,A,A