modular arithmetic with exponents

I'm looking at the solution manual of a book and it lists a solution for

$$[19^3\mod {23}]^2 \pmod {31} \equiv [(-4)^3\mod {23}]^2 \pmod {31} \equiv [-64\mod {23}]^2 \pmod {31}\equiv 5^2 \pmod{31} = 25$$

How does it get from $[19^3\mod {23}]^2 \pmod {31}$ to $[(-4)^3\mod {23}]^2 \pmod {31}$?

in other words where does the transformation from $19^3$ to $(-4)^3$ come from?

• $19 \pmod {23} = -4 \pmod {23}$ – Amzoti Nov 9 '13 at 5:33

The important thing is that it is from $19^3 \pmod {23}$ to $(-4)^3 \pmod {23}$ This works because $19 \equiv -4 \pmod {23}$ You lost that in going to the final question.