Solution (source code)

= Solution

In a <direct product of groups>, $(a,b)^r=(a^r,b^r)$. Thus a finite order for $(a,b)$ makes both coordinate orders finite. Conversely, if their orders are $p$ and $q$, the least positive exponent annihilating both is their <least common multiple>. Hence
$$
\boxed{\operatorname{ord}(a,b)=\operatorname{lcm}(p,q)}
$$
when both orders are finite; if either coordinate has infinite order, so does $(a,b)$.