402659: GYM100834 H Polycarp and Chains

Memory Limit:512 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

H. Polycarp and Chainstime limit per test2 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard output

Polycarp has got a set of N slots, there is one adornment in each slot. Each adornment has got a peculiar number — integer within the interval [1... N]. Polycarp has also got a set of M base and K compound operations. Base operations are called chains. Each chain with the number i is set by the number bli and numbers bi, 1, ..., bi, bli. All bi, j numbers are integers, they are different for each chain and belong to the interval [1... N]. It means the following: the adornment from the position bi, j goes to position bi, j + 1 for 1 ≤ j < bli. The adornment from the position bi, bli goes to position bi, 1. Compound operation with number i is described as follows: numbers cli and cli of a couple of numbers coi, j and cci, j are selected. Each couple means to use the chain coi, j cci, j times.

Polycarp carries out experiments with this set. Before starting each experiment the i-th adornment is placed into slot i. The experiment i is described by eli and eli couple of numbers eoi, j and eci, j. Each couple means to use the compound operation eoi, j eci, j times. Polycarp is eager to know what there will be in each slot after the recurrent experiment is carried out.

Input

The first line contains integer N, 1 ≤ N ≤ 100 — the number of slots and adornments.

The second line contains integer M, 1 ≤ M ≤ 100 — the number of chains. The descriptions of the chains are in the next M lines. The chain is described by bli, 1 ≤ bli ≤ N and different integers bi, j within the interval [1... N].

The next line contains integer K, 1 ≤ K ≤ 100 — the number of compound operations. Their descriptions are in the next lines. Each compound operation is defined by the number 1 ≤ cli ≤ 100 — the number of used chains. Next cli lines include couples of integers coi, j and cci, j, 1 ≤ coi, jM, 1 ≤ cci, j ≤ 109. The couples of integers and their quantity are in the separate lines.

The integer L, 1 ≤ L ≤ 100 is in the next line — the number of experiments. The next lines include their descriptions. Each experiment is defined by the integer 1 ≤ eli ≤ 100 — the number of used compound operations. In the next eli lines there are integers eoi, j and eci, j, 1 ≤ eoi, jK, 1 ≤ eci, j ≤ 109. The couples of numbers and their quantity are in separate lines.

Output

Output N numbers in a separate line for each experiment — which number of adornment is situated in the slot i for all integers i within the interval [1... N].

ExamplesInput
7
2
4 1 2 3 4
3 4 5 7
2
1
1 1
1
2 1
3
1
1 1
1
2 1
2
1 1
2 1
Output
4 1 2 3 5 6 7 
1 2 3 7 4 6 5
4 1 2 7 3 6 5

加入题单

算法标签: