The issue is to give explicit solutions $(A,B)$ to relationship :
$$AB-BA=\underbrace{\begin{pmatrix}p & \ \ q\\
r& -p\end{pmatrix}}_C\tag{1}$$
We are going to consider 3 cases, from the most general to the most particular.
- Let us assume first $p \neq 0$. Relationship (1) is verified by taking :
$$A:=\begin{pmatrix}0& p\\
0 & r\\ \end{pmatrix} \ \ \text{and} \ \
B:=\begin{pmatrix}0&0\\
1 & q/p\end{pmatrix}.\tag{2}$$
$$A:=\tfrac{1}{2(q+r)}\begin{pmatrix}r& -q\\
r& -q\end{pmatrix} \ \ \text{and} \ \
B:=\begin{pmatrix}\ \ q&\ \ q\\
-r&-r\end{pmatrix}\tag{3}$$
to get $$AB-BA=\begin{pmatrix}0 & q\\
r& 0\end{pmatrix}.$$
- Case $p=0$ and $r=-q$ : take :
$$A:=\begin{pmatrix}1& 1\\
1 & 0\\ \end{pmatrix} \ \ \text{and} \ \
B:=\begin{pmatrix}0&q\\
q & 0\end{pmatrix}.\tag{4}$$
giving
$$AB-BA=\begin{pmatrix}\ \ 0& q\\
-q & 0\\ \end{pmatrix} .$$
Remark about the degrees of freedom we have for (2), (3) and (4) :
Out of relationship (2) for example (the same is true for (3) and (4)), it is possible to generate a lot of other solutions to (1). For example by taking, for any $a$ and any $b$ :
$$A:=\begin{pmatrix}a& p\\
0 & a+r\\ \end{pmatrix} \ \ \text{and} \ \
B:=\begin{pmatrix}b&0\\
1 & b+q/p\end{pmatrix}.\tag{5}$$
The idea behind (5) is in fact very natural : if in (1), for a given $C$, we have a solution $(A,B)$, then, for any $k$, $(A,B+kI_2)$ is as well a solution because we still have
$$A(B+kI_2)-(B+kI_2)A = C.$$
(and $(A+k'I_2,B)$ as well) i.e., we can add a multiple of the identity matrix, to any of the solution matrices without changing the result. More generally, we can add to $B$ any polynomial $p(A)$ in $A$ :
$$A(B+p(A))-(B+p(A))A = C,$$
and, of course, to $A$ any polynomial in $B$.