f(x) = If[1 ≤ x ≤ 16, x^(2) + (6 * x)]
g(x) = If[16 ≤ x ≤ 31, (2.5 * x^(2)) - (40.5 * x) + 360]
h(x) = If[31 ≤ x, (4.5 * x^(2)) - (162.5 * x) + 2220]
p(x) = If[1 ≤ x ≤ 14, (2 * x) + 5]
q(x) = If[15 ≤ x ≤ 30, (5 * x) - 38]
r(x) = If[31 ≤ x, (9 * x) - 158]