Given the j-function,
$$j(\tau) = {1 \over q} + 744 + 196884 q + 21493760 q^2 + \dots$$
It seems that for $\tau = \frac{1+\sqrt{-d}}{2}$ and $d=12n+7$, then it has the form,
$$j(\tau) = 12^3(1-x^2)^3\tag1$$
where $x$ is an algebraic number of degree equal to the class number $h(-d)$. For example, if $d=31$, then $x$ is a root of,
$$8x^3 - 24x^2 - 90x - 81 =0\tag2$$
It is easy to solve for the real root of $(2)$ using Cardano's formula. However, as I saw in this link, it can also be expressed in the rather aesthetic form,
$$x = 1+\tfrac{\sqrt{19}}{2}\left(\left(\tfrac{13-\sqrt{93}}{13+\sqrt{93}}\right)^{1/2}\left(\tfrac{\sqrt{31}+\sqrt{27}}{\sqrt{31}-\sqrt{27}}\right)^{1/3}+\left(\tfrac{13+\sqrt{93}}{13-\sqrt{93}}\right)^{1/2}\left(\tfrac{\sqrt{31}-\sqrt{27}}{\sqrt{31}+\sqrt{27}}\right)^{1/3}\right)\tag3$$
For $d = 139$, we have,
$$x^3 - 141x^2 + 351x - 243 = 0\tag4$$
Question: How do we express the real root of $(4)$ in a similar form to $(3)$? If it is not possible, what are the special conditions on the coefficients of a cubic so that it is expressible as such?

After some tinkering, I managed to answer partially my question and it turns out it involves Pell equations.
A. For $d = 31$. Given the Cardano solution to the cubic,
$$8x^3-24x^2-90x-81=0\tag1$$
$$x = 1+\frac{1}{2}\Big(\frac{187+9\sqrt{93}}{2}\Big)^{1/3}+\frac{1}{2}\Big(\frac{187-9\sqrt{93}}{2}\Big)^{1/3}\tag{1a}$$
it seems that whoever posted the aesthetic version in the j-function link essentially factored the expression within the cube root as,
$$\alpha = \frac{187+9\sqrt{93}}{2} = \beta^3\, U$$
hence a product of a cube and $U$ as a fundamental unit. Of the $12$ (out of $16$) fundamental discriminants with class number $h(-d) = 3$, and with form $12n+7$, there were only three such that the fundamental unit $p+q\sqrt{d}$ had small $p,q$, namely $d=31,\,331,\,547$.
Thus, $(1a)$ can then be alternatively expressed as,
$$x = 1+\tfrac{1}{4}\big(13-\sqrt{93}\big)\,U_1^{1/3}+\tfrac{1}{4}\big(13+\sqrt{93}\big)\,U_1^{-1/3}$$
where,
$$U_1 = \frac{\sqrt{31}+\sqrt{27}}{\sqrt{31}-\sqrt{27}}=\frac{29+3\sqrt{93}}{2} $$
with $29^2-93\cdot3^2=4$ and it will take only a little tweaking to bring $x$ to the form in the post, as with the two below.
B. For $d = 331$.
$$x^3 - 3957 x^2 - 5481 x - 11907 = 0\tag2$$
$$x = 1319+2\big(5773-182\sqrt{993}\big)\,U_2^{1/3}+2\big(5773+182\sqrt{993}\big)\,U_2^{-1/3}$$
where,
$$U_2 = \frac{\sqrt{1324}+\sqrt{1323}}{\sqrt{1324}-\sqrt{1323}}=2647+84\sqrt{993}$$
Note that fundamental solution of the Pell equation $2647^2-993\cdot 84^2=1$.
C. For $d = 547$.
$$x^3 - 60081 x^2 - 152361 x - 100359=0\tag3$$
$$x = 20027+2\big(103420-2541\sqrt{1641}\big)\,U_3^{1/3}+2\big(103420+2541\sqrt{1641}\big)\,U_3^{-1/3}$$
where,
$$U_3 = \frac{\sqrt{2188}+\sqrt{2187}}{\sqrt{2188}-\sqrt{2188}}=4375+108\sqrt{1641}$$
and $4375^2-1641\cdot 108^2=1.$
Of course, the remaining question is why $\alpha$ can be factored as $\alpha=\beta^3\, U$ with $U$ as a fundamental unit.