#P2290. House Numbers

House Numbers

Description

NarmakSung has a hardware shop that makes new digit plates for house numbers. If a house number is 195, for example, he has to create one plate for digit 1, one for digit 9, and one for digit 5. But, the orders are not always that simple. He may get orders to make digit plates, for example, for all houses in one side of a street.

Since making several plates of the same digit costs much less than making all digits for each house one by one, he wants to know, for a big order he receives, how many of each digit plate he has to make.

Input

The first number in the input line, t (1 <= t <= 10) is the number of orders. Following this, t orders are written in the input. Each order starts with a line containing a street name, an arbitrary string of length at most 50 characters. The second line contains a single integer N (1 <= N <= 10), the number of sub-orders, followed by N lines of sub-orders. Sub-orders are of three kinds:

  • A single house number: in this case, the sub-order line contains only a single integer n (1 <= n <= 9999)
  • A series of house numbers: in this case, the sub-order line starts with a '+', followed by three integer numbers a, b, c (1 <= a, b, c <= 9999). This means that NarmakSung has to make plates for house numbers from a up to b with distance of c. That is, digit plates have to be made for house numbers a, a+c, a+2c, ..., b. We assume that a < b, b - a is a multiple of c, and c <= b - a.
  • A series of house numbers to be excluded: this kind of sub-orders specifies that a series of house numbers should not be made. In this case, the sub-order line starts with a '-', followed by three integer numbers with exactly the same conditions as in the previous case.

Note that if a house number is ordered more than once in two separate sub-orders, it is counted only once if it is not excluded at all (like number 100 in the second test case in the sample input). Also, if a house number is excluded somewhere in the test case, it cancels any order for that number, even if it appears later in the test case (like number 500 in the second sample). Note that it is possible to exclude some numbers that do not appear in other orders at all. In this case, these numbers are ignored (like 900 in the second sample).

Output

One set of output data is written for each input order consisting of 13 lines. Each set starts with one line containing the street name exactly as appeared in the input order. The next line must be of the form C addresses where C is the total number of house numbers to be made. In the special case of C = 1, the output line should be 1 address. The next 10 lines should be of the following form: Line i should contain the number of digit plates needed to be made for digit i. These 10 lines are on the format "Make X digit Y" where X is how many copies of digit Y they need to make. The last line states the total number Z of digits needed, on the format "In total Z digits". If there is only one digit to produce, it should say, "In total 1 digit", in order to be grammatically correct. The output should be case-sensitive.

2 
Azadi Street
2
+ 101 103 2
275 
Sharif Highway
3
100
- 500 900 100
+  100 800 100
Azadi Street
3 addresses
Make 2 digit 0
Make 3 digit 1
Make 1 digit 2
Make 1 digit 3
Make 0 digit 4
Make 1 digit 5
Make 0 digit 6
Make 1 digit 7
Make 0 digit 8
Make 0 digit 9
In total 9 digits
Sharif Highway
4 addresses
Make 8 digit 0
Make 1 digit 1
Make 1 digit 2
Make 1 digit 3
Make 1 digit 4
Make 0 digit 5
Make 0 digit 6
Make 0 digit 7
Make 0 digit 8
Make 0 digit 9
In total 12 digits

Source

Tehran 2003