Given the Lagrangian in 6-dimensional spacetime:
$$ L = \frac{1}{2}\partial^\mu\phi\partial_\mu\phi - \frac{1}{2}m^2\phi^2-\frac{g_3}{3!}\phi^3.\tag{1} $$
The Lagrangian with counterterms is given by
$$ L_c = \frac{1}{2}Z\partial^\mu\phi\partial_\mu\phi - \frac{1}{2}(m^2+\delta_m^2)\phi^2\color{red}{-Z_1g_1\phi}-Z_3\frac{g_3}{3!}\phi^3\\ = \frac{1}{2}\partial^\mu\phi\partial_\mu\phi - \frac{1}{2}m^2\phi^2-\frac{g_3}{3!}\phi^3 +\frac{1}{2}(\partial^\mu\phi\partial_\mu\phi)\delta_z-\frac{1}{2}\delta_m^2\phi^2\color{red}{-\delta_1\phi}-\delta_3\frac{\phi^3}{3!}.\tag{2} $$
How does the term $\color{red}{-Z_1g_1\phi}$ and $\color{red}{-\delta_1\phi}$ appear? The superficial degree of divergence of a graph in 6 dimensions could be found as $$ \omega = 6-2n\tag{3} $$
where $n$ is the number of external lines. To find the one-particle irreducible divergent graphs, we can set $n = 1,2,3$. It seems to me that those terms in the Lagrangian are associated with the $n=1$ case.
However, for $n = 2$ and $3$, it's more clear to me where the counterterms come from, because $\delta_m$, $\delta_z$, and $\delta_3$ are 'attached' to some existing quantities. I don't know how to understand why $\color{red}{-Z_1g_1\phi}$ and $\color{red}{-\delta_1\phi}$ are added to the Lagrangian.
Also, I'm not confident with implementing $Z$ factors. I would really appreciate it if someone could explain a bit about the first line of $L_c$. Why and how the $Z$ factors are attached?