See Remark 2.2 here.

If you expand $p/q$ into a continued fraction then the successive convergents, as columns of a $2 \times 2$ matrix, have determinant $\pm 1$. Provided $p/q$ is in reduced form and $q > 0$, the last convergent $p_n/q_n$ in the continued fraction for $p/q$ will have $p_n = p$ and $q_n = q$. Let the second to last convergent be $p_{n-1}/q_{n-1}$. Then $p_{n-1}q_n - q_{n-1}p_n = \pm 1$, and it is easy to pass from such an equation to a $2 \times 2$ integral matrix with determinant $1$ and first column $\binom{p}{q}$.

Let's illustrate these algorithms by starting with the second question on the rational number $p/q = 37/11$, which is in reduced form. What is a matrix in ${\rm SL}_2(\mathbf Z)$ with first column $\binom{37}{11}$? The continued fraction of $37/11$ is $[3,2,1,3]$ and the successive convergents in this continued fraction are $3/1$, $7/2$, $10/3$, and $37/11$. Using the last two convergents, we obtain $\det(\begin{smallmatrix}10&37\\3&11\end{smallmatrix}) = -1$, so $11 \cdot 10 - 37 \cdot 3 = -1$, so $37(3) - 11(10) = 1$. Thus the matrix $A = (\begin{smallmatrix}37&10\\11&3\end{smallmatrix})$ is in ${\rm SL}_2(\mathbf Z)$ with first column $\binom{37}{11}$, so $A(\infty) = 37/11$.

Next, for the matrix $A = (\begin{smallmatrix}37&10\\11&3\end{smallmatrix})$ in ${\rm SL}_2(\mathbf Z)$, how can we write $A$ in terms of $S$ and $T$? For this we will use a continued fraction for the first column ratio $37/11$ using nearest integers from above rather than from below: $37/11 = 4 - 1/(2 - 1/(3 - 1/(2 - 1/2)))$. Using the entries $4, 2, 3, 2$, and $2$, form the matrix product $M = T^4ST^2ST^3ST^2ST^2S$. Its first column will be $\binom{37}{11}$ but its second column might not match that of $A$, so $M^{-1}A$ will be a power of $T$. Indeed, $M = (\begin{smallmatrix}37&-27\\11&-8\end{smallmatrix})$ and $M^{-1}A = (\begin{smallmatrix}1&1\\0&1\end{smallmatrix}) = T$, so
$$
A = MT = T^4ST^2ST^3ST^2ST^2ST.
$$

Geometry of Continued Fractions.$\endgroup$