Project Team Vacation Schedule

No attempts yetTime limit1sMemory limit512 MB

Problem

A team of mm members runs a project over nn consecutive working days, numbered 1 to nn. You draw up the vacation schedule of the members.

Every member works on at least pp and at most pp' of the nn working days. On working day ii the number of members who work must be at least qiq_i and at most qiq_i', for i=1,,ni = 1, \dots, n.

Each member also submits a list of vacation plans

(d1,[r1,r1]),(d2,[r2,r2]),,(dk,[rk,rk]).(d_1, [r_1, r_1']), (d_2, [r_2, r_2']), \dots, (d_k, [r_k, r_k']).

The plan (dt,[rt,rt])(d_t, [r_t, r_t']) means the member takes at least dtd_t vacation days among the working days rt,rt+1,,rtr_t, r_t + 1, \dots, r_t'. The member also wants to work on every day outside the union of those periods, t=1k{r:rtrrt}\bigcup_{t=1}^{k}\{r : r_t \le r \le r_t'\}, so a member never takes a vacation day outside the listed periods.

A vacation plan does not fix which days the vacation days are. A member holding the plan (2,[7,9])(2, [7, 9]) can take the two days {7,8}\{7, 8\}, {7,9}\{7, 9\} or {8,9}\{8, 9\}, and can also take all three days {7,8,9}\{7, 8, 9\}. For a plan such as (2,[3,4])(2, [3, 4]) the vacation days are fixed.

An assignment of vacation days to every member that satisfies all the constraints above is a vacation schedule. Members are numbered 1 to mm. Decide whether a vacation schedule exists, and print one when it does.

Input

Read from standard input. The first line contains four positive integers mm, nn, pp and pp', where m100m \le 100, n100n \le 100 and ppnp \le p' \le n.

Each of the next nn lines contains two positive integers qiq_i and qiq_i' for i=1i = 1 to nn, where qiqimq_i \le q_i' \le m.

Each of the next mm lines holds the vacation plans of one member, the jj-th of these lines belonging to member jj. The plans (d1,[r1,r1]),,(dk,[rk,rk])(d_1, [r_1, r_1']), \dots, (d_k, [r_k, r_k']) are given as a sequence of 3k+13k + 1 positive integers: k,d1,r1,r1,d2,r2,r2,,dk,rk,rkk, d_1, r_1, r_1', d_2, r_2, r_2', \dots, d_k, r_k, r_k'. A member has at most 20 vacation plans. For every tt, rtrtnr_t \le r_t' \le n and dtrtrt+1d_t \le r_t' - r_t + 1. Also r1<r2<<rkr_1 < r_2 < \dots < r_k, and the periods [ra,ra][r_a, r_a'] and [rb,rb][r_b, r_b'] share no working day when aba \ne b.

Output

Write to standard output. The first line contains 1 when a vacation schedule satisfying every constraint exists, and -1 when none exists.

When and only when the first line is 1, print mm more lines. The jj-th of them describes the vacation schedule of member jj as the number of vacation days followed by the vacation days in increasing order.

Several vacation schedules can satisfy all the constraints. In that case print the lexicographically smallest one, under the following comparison. Write a schedule as a table of mm rows and nn columns whose entry in row jj and column ii is 0 when member jj works on day ii and 1 when member jj is on vacation on day ii. Read the table row by row, member 1 first, and inside a row day 1 first, which gives a sequence of 0s and 1s. Among all valid schedules, print the one whose sequence is lexicographically smallest.

The same rule stated as a procedure: walk through the members in order 1 to mm and, for each member, through the days in order 1 to nn. Let the member work on the current day when at least one valid schedule keeps every decision already made and has that member working on that day. Otherwise the member takes that day off.