Religion as a chain of memory