Quantum channels with a finite memory