The first subproblem should be easier to solve in comparison with the second.
let's take a 4 digit number.
Recall that the decimal expansion of any number greater than 10 is of the form ...1000a4 + 100a3 + 10a2 + a1, where all ai are positive integers Rearranging the digits of the number will also lead to a similar expansion, say 1000a3 + 100a4 + 10a1 + a2
Subtraction of the second from the first, or vice versa, will lead to a difference which will be like
900 a4 + (-900) a3 + 9a2 - 9a1.
It isn't a big surprise that the difference is a multiple of 9.