4. The numbers $1,2,3,4$ and 5 are used once each in some order substituting for the letters in the series of powers $\left.M^{\left(A^{\left(T^{S}\right)}\right)}\right)$. In how many of the arrangements is the units digit of the value of this expression equal to 1 ?
Solution
If $M=2,4$ or 5 , the expression must be even or a multiple of 5 respectively, so cannot end in 1 .
If $M=1$, the answer will always be 1 , hence end in 1 . There are 24 ways of arranging the other four numbers to substitute for the remaining letters.
If $M=3$, the answer will end in 1 precisely when the power is a multiple of 4 because the last digits of powers of 3 follow the repeating pattern of 3, 9, 7 and 1. This occurs in one of two ways.

The first is whenever $A=4$. There are 6 ways of arranging the other three numbers to substitute for the remaining letters.
The second is when $A=2$ and its power is larger than 1 . This happens as long as $T \neq 1$. There are 2 choices for $T$ and, for each of those, two ways of arranging the other two numbers to substitute for the remaining letters, which gives 4 ways.
The total number of arrangements is $24+6+4=34$.
Alternative
Consider which letter represents 1 because all the letters after that have no effect on the value of the expression.
If $M=1$, there are 24 ways as above.
In the remaining cases, $M$ cannot be 2, 4 or 5 as above so must be 3 and the power of 3 must be a multiple of 4 .
If $A=1$, there are no ways.
If $T=1, A$ must be 4 , which gives 2 ways to arrange the values of $H$ and $S$.
If $H=1, A$ must be 2 or 4 and any arrangements for $T$ and $S$ work after that. This gives 2 ways to arrange the values of $T$ and $S$, so 4 arrangements in total.

If $S=1, A$ must be 2 or 4 and any arrangements for $T$ and $H$ work after that. This gives 2 ways to arrange the values of $T$ and $S$, so 4 arrangements in total.
Therefore, there are $24+2+4+4=34$ arrangements.