Liquid Crystal Developers (LCD) is a top-notch manufacturer of alarm clocks. Alarm clocks are one of the few things that have not changed dramatically since their invention. The market department at LCD has devised a plan to manufacture customizable alarm clocks in order to attract more customers. The new alarm clocks could be programmed by the owner to display digits with heterogeneous sizes, that is, display amplified versions of the traditional digits according to the user’s preference. A traditional digit, or simply a digit, is a nonnegative integer d (0 ≤ d ≤ 9). A digit is displayed in a 3 × 3 grid consisting of dots (decimal ASCII code 46), underscores (decimal ASCII code 95), and bars (decimal ASCII code 124), as depicted in the following figure: .. ... .. .. ... |.| ..| .| .| || || ..| |. .| ..| .. .. .. .. .. |. |. ..| || || .| || ..| || .| 0123456789 An amplified digit is a pair (d,f) consisting of a digit d and a positive integer factor f (0 ≤ d ≤ 9, f ≥ 1). An amplified digit (d, f) is displayed in a grid with (2·f)+1 rows and f +2 columns. Each such a grid consists of underscores, dots, and bars, in which underscores and bars are expanded horizontally and vertically, respectively, by a factor of f with respect to the display of digit d. Dots are used to fill any space in the grid not corresponding to an underscore or a bar. As an example, consider the following figure displaying five amplified digits: .. |...... ...... |...... |....| |...... |....| ..... |...... |....| ....| |. |____| ....| ......| .....| ....| ......| .....| ....| ......| .....| ....| ......| .....| ....| ._| (4,4) (1,3) (5,5) .. ...| .| |... |. .. |....... |....... |....... |....... |....... |. |......| |......| |......| |......| |......| || The new alarm clocks display aligned vertically with respect to amplified digits are separated by a column of dots and any space that does not contain an underscore or a bar is represented by a dot. The following figure displays the sequence (4, 4), (1, 3), (5, 5), (2, 2), (6, 6) of amplified digits: ...........................__. ..........................|....... (2,2) (6,6) sequences of amplified digits. The amplified digits in a display are their bottom rows. Moreover, in the display, each two consecutive
2/3 .....................|....... .............|............|....... .............|............|....... |....|.......|............|....... |....|.......|............|_. |....|.....|.|_____.......|......| |____|.....|.......|....|......| .....|.....|.......|....|.|......| .....|.....|.......|..|.|......| .....|.....|.......|.|....|......| .....|.....|..|.|..|___| As a member of the programming department at LCD, you have been assigned the implementation of an algorithm for sampling the display of the new alarm clocks. Input The input consists of several test cases. The first line in a test case contains a positive integer N (1 ≤ N ≤ 104), representing the number of amplified digits in the display. Each one of the following N lines contains two blank-separated integers di and fi (0 ≤ di ≤ 9, 1 ≤ fi ≤ 105 for each 1 ≤ i ≤ N), representing an amplified digit (di, fi). The next line contains a nonnegative integer M (0 ≤ M ≤ 104), representing the number of samples for the display. Then M lines follow, each containing two blank- separatedintegersxj andyj (0≤xj <c,0≤yj <rforeach1≤j≤M),representingasample. The positive integers c and r denote the total number of columns and rows in the displayed sequence of amplified digits, respectively. The last test case is followed by a line containing a single zero value. Output For each test case with N displayed amplified digits (d1,f1), ..., (dN,fN) and M samples (x1,y1), ..., (xM,yM), M lines must be printed, each containing either an underscore, a dot, or a bar. The j-th line in the output (1 ≤ j ≤ M) must identify the character at column xj and row yj in the display of (d1, f1), . . . , (dN , fN ). Coordinate (0, 0) identifies the character in the leftmost column and bottom row (i.e., a coordinate represents a point in the first quadrant of the integer Cartesian coordinate system with origin in the leftmost column and bottom row). Sample Input 5 44 13 55 22 66 7 50 60 13 5 33 12 32 12 57 58 3
3/3 12 11 74 4 13 8 13 7 08 71 0 Sample Output | . | . _ | . _ . . |