The government of Impecunia levies no taxes; instead it raises money by selling Bonus Bonds.
Every bond carries a 10-digit serial number. In that serial number the 3rd digit from the left (equivalently, the 8th digit from the right) is the region code, a single digit from 0 to 9 that identifies the region where the bond was sold. The other nine digits identify the bond within its region.
For security, no bond may carry a serial number that is entirely zeros. Because the central region uses the code 0, its bonds begin at 0000000001. Every other region has a non-zero region digit, so even with all its other digits zero the number is not entirely zero, and its bonds may begin at that value.
Within a single region the region digit never changes, so bonds are issued in increasing order of the nine-digit number formed by the other nine positions. Thus, given the serial number of the next bond to be sold in some region, the bonds already sold are exactly those running from that region's smallest allowed serial number up to the one just before the next bond.
Each month winning numbers are drawn per region. To audit the drawing equipment, the state auditors need to know, for one chosen character position, how the digits 0 through 9 are distributed at that position among all the bonds already sold in a region.
Given the serial number of the next bond to be sold in a region and a character position, write a program that prints how many of the already-sold bonds in that region have each digit 0, 1, ..., 9 at that position.
For implementation, note that deleting the region-code digit from a 10-digit serial leaves a nine-digit number (its sequence number). Let next be the sequence number of the next bond to be sold. The already-sold bonds have sequence numbers from L to next - 1, where L is 1 for the central region (code 0) and 0 for every other region. Character positions are counted from the left over the full 10-digit serial, and position 3 is always the region code.
The input consists of several lines. Each line contains a 10-digit serial number (the next bond to be sold in some region) and an integer p (1 to 10, counted from the left) giving the character position to examine, separated by a space. Leading zeros are significant (the serial is always exactly 10 digits). A region may appear on several lines, or not at all. The input ends with the line 0000000000 0, which must not be processed.
For each input line, print one table. Each table has ten rows, one for each digit 0 through 9 in order. Row d holds the number of already-sold bonds in that region whose digit at the requested position equals d. Print each count right-justified in a field of width 11. Separate consecutive tables with a single blank line.