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 ...1000a_{4}+ 100a_{3}+ 10a_{2}+ a_{1}, where all a_{i}are positive integers Rearranging the digits of the number will also lead to a similar expansion, say 1000a_{3}+ 100a_{4}+ 10a_{1}+ a_{2}

Subtraction of the second from the first, or vice versa, will lead to a difference which will be like

900 a_{4}+ (-900) a_{3}+ 9a_{2}- 9a_{1}.

It isn't a big surprise that the difference is a multiple of 9.