Solution (source code)

= Solution

Let $r_i$ be the <probability> of returning to $i$ after its first departure. Transience means $r_i<1$; in particular $q_i>0$. By the <Strong Markov property>, the number $N$ of visits, including the initial visit, has the <geometric distribution> $\mathbb P(N=n)=(1-r_i)r_i^{n-1}$, $n\ge1$. The <holding times> of these visits are independent $\operatorname{Exp}(q_i)$ variables and are independent of the jump-chain return decisions.

For the total <occupation time of a continuous-time Markov chain> $T_i$ and $s\ge0$, summing over $N$ gives
$$
\mathbb E_i e^{-sT_i}
=\sum_{n\ge1}(1-r_i)r_i^{n-1}\left(\frac{q_i}{q_i+s}\right)^n
=\frac{q_i(1-r_i)}{s+q_i(1-r_i)}.
$$
Uniqueness of the <Laplace transform> identifies
$$
\boxed{T_i\sim\operatorname{Exp}\bigl(q_i(1-r_i)\bigr)}.
$$
Starting elsewhere adds an atom at zero if the state might never be hit; the purely exponential conclusion uses the specified initial state $i$.