$$\textbf{Step 1: Use mean and variance formula of binomial distribution to find probability of failure.}$$
$$\text{Mean}$$ $$=n
p=18$$ $$......(1)$$
$$\text{Variance}$$ $$=n
p q=12$$ $$......(2)$$
$$\text{Substitute, }np=18 \text{ in equation (2), we get}$$
$$18 \times q=12$$
$$\text{Probability of failure}=q=\dfrac{2}{3}$$ $$......(3)$$
$$\textbf{Step 2: Find probability of success and then number of trails.}$$
$$p=1-q$$
$$\Rightarrow p=1-\dfrac{2}{3}$$
$$\Rightarrow p=\dfrac{1}{3}$$
$$ \begin{aligned} &n p=18 \\\\ &n=\dfrac{18}{p} \quad \quad \quad \textbf{[From eqn(i)]}\end{aligned} $$
$$\Rightarrow n=\dfrac{18}{\dfrac{1}{3}} $$
$$\Rightarrow n=18 \times 3 $$
$$\Rightarrow n=54$$
$$\textbf{Hence, number of trails }\boldsymbol{=n=54.}$$