The Lagrangian mechanics of N-body system with arbitrary multipole moments