Link to my Prob is Lyra and Alethiometer
For input
998AA989BB999
your code returns 9899, correct result is 9999.