Functions \( g \) and \( h \) are defined on \( n \) constants, \( a_0, a_1, a_2, a_3, \ldots, a_{n-1} \), as follows:
\[
g(a_p, a_q) =
\begin{cases}
a_{|p - q|}, & \text{if } |p - q| \leq (n - 4) \\
a_{n - |p - q|}, & \text{if } |p - q| > (n - 4)
\end{cases}
\]
\[
h(a_p, a_q) = a_k, \quad \text{where } k \text{ is the remainder when } (p + q) \text{ is divided by } n.
\]