Note here that when you write $(l,m,0)$ and $(p,0,q)$, these are the unit vectors along the respective lines.(Check on the definition of a direction cosine)
So, this'd mean that
$$\sqrt{l^2+m^2}=1 ~~ \implies \frac1{\sqrt{l^2+m^2}}=1 \tag{1}$$
Similar reasoning allows us to deduce
$$\sqrt{p^2+q^2}=1 ~~ \implies \frac1{\sqrt{p^2+q^2}}=1\tag{2} $$
Now note that $(l,m,0)$ and $(p,0,q)$ are perpendicular, so
$$(l,m,0) \cdot(p,0,q)=0~~ \implies lp=0$$
One of them has to be zero right? Let's assume that $l=0$. Then from our result $(1)$, $m=1$ (it makes sense too, right? if $m \neq 1$ then our vector wouldn't be a unit vector would it?).
So one of our unit vectors reduces just to $(0,1,0)$, which is just a vector along the y-axis, or $\hat{\jmath}$.And what other unit vector do you know with the y-component $0$ (in the form $(p,0,q)$) and perpendicular to $\hat{\jmath}$? Obviously, it is the vector $\hat{k}$, or the vector $(0,0,1)$.
Now you should notice that from our deductions, $m=q=1$.
If you revisit $(1)$ and $(2)$ you have
$$q=\frac1{\sqrt{l^2+m^2}}$$
and,
$$m=\frac1{\sqrt{p^2+q^2}}$$
Hope it Helps!