Optimization in multivalued logic. Optimal strings with given patterns
As stated, it looks like the solution is trivial: if $\omega$ is the largest value in the underlying domain of values, then $\omega \omega \cdots \omega$ is the optimal value for the tuple.

Let's take your example, templates $AAAAB$, $AAABB$, and $AAABC$.  Suppose the underlying domain of allowable values is $\{0,1,\dots,9\}$.  Then $99999$ is the optimal tuple.  It satisfies $AAAAB$ by the assignment $A_1A_2A_3A_4B_5$.  It satisfies $AAABB$ by the assignment $A_1A_2A_3B_4B_5$.  In fact it satisfies every template.  For any template, there exists an assignment of values to each $X_i$ that makes the tuple $99999$ match that template: just assign the value $9$ to every $X_i$, for all levels $X$ and all variable indices $i$.

Perhaps you meant to provide both the templates and the assignment of values (all $m^2$ values for all the $X_i$'s, where $X$ and $i$ range over all possibilities) as input.