Every magnet has two poles designated north and south. Like poles of two or more magnets repel each other, but unlike poles attract each other.
When very small, disk-shaped magnets are placed onto a smooth, lubricated table top, each with the same pole pointed upward, they arrange themselves into a grid like the one first shown above. That equalizes the magnetic forces acting on each magnet from all the other magnets to the extent possible. But if the grid is squeezed, or compressed, from the sides, the grid begins to deform. Then. suddenly. one of the tiny magnets leaps into the air followed immediately by others.
As they tumble in the air above the tabletop, being pushed and pulled by each other and all the ones still on the table, when a north pole and a south pole come together, they stick, forming long rods until no more are left flat on the table.
Isn’t sciencey stuff fascinating?