Consider common factors of pairs of these numbers. It may help to consider first the result for one track with p sectors and a knight's move of a steps forward and zero steps to the side for different values of p and a.

A convenient notation is to let (x,y) ? (x+s, y+t) denote a move of s steps clockwise and t steps outwards taking x and x+s modulo p and y and y+t modulo q.