So in your examples, observe that , and . (*)
Thus, it follows that , and .
I hope this clarifies things!
EDIT: You could also observe that
by what I said in (*).
Similarly, we also see that and .
The moral of the story: Fermat's Little Theorem holds as long as . But most solutions will be simplified so that they lie within the residue system . So I would recommend simplifying the expression first and then apply Fermat's little theorem.