move in a matrix using remainder