In reply to Rick Wicklin.

Ah, I see it now.
You want the pattern (0, 1, 2, 0, 1, 2, 0 ... for q=3) to be continuous before and after 0, whereas the pattern created by the remainder of the division will flip the pattern and sign around 0.