In this example we are multiplying two binomials so FOIL method can be used.
$$ \begin{aligned} \left( \color{blue}{ 5p+3}\right) \cdot \left( \color{orangered}{ 8p+7}\right) &= \underbrace{ \color{blue}{5p} \cdot \color{orangered}{8p} }_{\text{FIRST}} + \underbrace{ \color{blue}{5p} \cdot \color{orangered}{7} }_{\text{OUTER}} + \underbrace{ \color{blue}{3} \cdot \color{orangered}{8p} }_{\text{INNER}} + \underbrace{ \color{blue}{3} \cdot \color{orangered}{7} }_{\text{LAST}} = \\ &= 40p^2 + 35p + 24p + 21 = \\ &= 40p^2 + 35p + 24p + 21 = \\ &= 40p^2+59p+21; \end{aligned} $$