Different poles : Attract
Similar Poles: Repulse
For the two upper magnets ( 1, 4 ) N-S , N-S ( so attraction )
For the two lower (2,3) S-S S-S ( repulsion )
Considering this case:
F = kQ1Q2/r^2 (coulomb law)
So F is inversely proportional to the distance so the more near the magnet to the main one , the more force it experiences.
Magnet 2 experiences the greatest repulsion force.