Solution (source code)

= Solution

Direct multiplication gives $A^3=B^2=-I$, so $\langle A\rangle$ has order $6$, $\langle B\rangle$ has order $4$, and their intersection is $\{I,-I\}$ of order $2$. For the <amalgamated free product>
$$
SL_2(\mathbb Z)=\langle A\rangle*_{\{\pm I\}}\langle B\rangle,
$$
the <Bass-Serre tree> has vertices
$$
SL_2(\mathbb Z)/\langle A\rangle
\sqcup
SL_2(\mathbb Z)/\langle B\rangle
$$
and edges $SL_2(\mathbb Z)/\{\pm I\}$. Each edge $g\{\pm I\}$ joins $g\langle A\rangle$ to $g\langle B\rangle$. Thus it is an infinite bipartite tree in which the $\langle A\rangle$-vertices have degree $3$ and the $\langle B\rangle$-vertices have degree $2$:
$$
\cdots\ {-}\ \bullet_2\ {-}\ \circ_3\ {-}\ \bullet_2\ {-}\ \circ_3\ {-}\ \bullet_2\ {-}\ \cdots,
$$
with a third branch leaving every $\circ_3$ vertex and the same pattern continuing on every branch.