Solution (source code)

= Solution

The group is the <direct product of groups> $\mathbb Z_p\times\mathbb Z_q$. Repeatedly adding $(1,1)$ returns to $(0,0)$ for the first time when both $p$ and $q$ divide the step number. Its <order of a group element> is therefore $\operatorname{lcm}(p,q)$. If $p,q$ are <coprime>, this is $pq$, so it generates every element:
$$
\boxed{G(p,q)\cong C_{pq}.}
$$
Explicitly, $[t]_{pq}\mapsto([t]_p,[t]_q)$ is the <Chinese remainder theorem> <group isomorphism>.

If $d=\gcd(p,q)>1$, every pair satisfies
$$
\frac{pq}{d}(n,m)=(0,0).
$$
Thus every element order divides $pq/d<pq$, and no element can generate the whole group. Hence
$$
\boxed{G(p,q)\text{ is cyclic exactly when }\gcd(p,q)=1.}
$$
This is the <cyclicity of a product of two finite cyclic groups>.