Bifurcation of free and forced vibrations for nonlinear wave and Kirchhoff equations via Nash-Moser theory