# Pyth, <s>22</s> 19 bytes

*3 bytes thanks to Jakube.*

    seSs.:RQ.n,L_MdCB.z

[Try it online.][try]

If we are allowed to print leading zeroes, the code is 18 bytes:

    eSs.:RQ.n,L_MdCB.z

[try]: https://pyth.herokuapp.com/?code=seSs.%3ARQ.n%2CL_MdCB.z&input=3%0A7423%0A1531%0A6810&debug=0