Nonstationary gravitational lenses and the Fermat principle