Explanation:
the law of cosine is what I call the enhanced Pythagoras for non right-angled triangles (or even for right-angled triangles, when we are looking for an angle different than the 90° angle).
in our case
b² = a² + c² - 2ac×cos(B)
b = sqrt(a² + c² - 2ac×cos(B))
therefore,
m = a²
n = c²
p = 2ac
q = cos(B)