why compass needle gets deflected when brought near a bar magnet