Sorry, was typing one-handed so couldn't explain more thoroughly. But if you go to the renfe site, you can search for the train schedule. Select "buscar horarios" (look for schedules), then on the next screen, select "todas las estaciones" (all stations). Select "buscar." Then select "F" & scroll down. Select Fromista, then select Palencia on the next screen. check the times & then you can search for trains to Madrid.