A number lock has N dials in a row. Each dial carries the digits 0 to 9 in order and shows one of them.
Turning a dial up changes the digit it shows from 0 to 1, from 1 to 2, and so on, with 9 going back to 0. Turning a dial down moves in the opposite direction.
You may turn several dials at the same time. Dials turned together must be adjacent, and they all move one step in the same direction. There is no limit on how many you turn at once. One such turn counts as one move.
For example, if the lock shows 123, a single move produces 012 by turning every dial down, 234 by turning every dial up, 133 by turning the middle dial up, or 013 by turning the first two dials down. 224 cannot be reached in one move.
Given the current state S and the target state T, write a program that finds the smallest number of moves needed to turn S into T.