spiral matrix, range and direction flag