A team of m members runs a project over n consecutive working days, numbered 1 to n. You draw up the vacation schedule of the members.
Every member works on at least p and at most p′ of the n working days. On working day i the number of members who work must be at least qi and at most qi′, for i=1,…,n.
Each member also submits a list of vacation plans
(d1,[r1,r1′]),(d2,[r2,r2′]),…,(dk,[rk,rk′]).
The plan (dt,[rt,rt′]) means the member takes at least dt vacation days among the working days rt,rt+1,…,rt′. The member also wants to work on every day outside the union of those periods, ⋃t=1k{r:rt≤r≤rt′}, 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]) can take the two days {7,8}, {7,9} or {8,9}, and can also take all three days {7,8,9}. For a plan such as (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 m. Decide whether a vacation schedule exists, and print one when it does.
Read from standard input. The first line contains four positive integers m, n, p and p′, where m≤100, n≤100 and p≤p′≤n.
Each of the next n lines contains two positive integers qi and qi′ for i=1 to n, where qi≤qi′≤m.
Each of the next m lines holds the vacation plans of one member, the j-th of these lines belonging to member j. The plans (d1,[r1,r1′]),…,(dk,[rk,rk′]) are given as a sequence of 3k+1 positive integers: k,d1,r1,r1′,d2,r2,r2′,…,dk,rk,rk′. A member has at most 20 vacation plans. For every t, rt≤rt′≤n and dt≤rt′−rt+1. Also r1<r2<⋯<rk, and the periods [ra,ra′] and [rb,rb′] share no working day when a=b.
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 m more lines. The j-th of them describes the vacation schedule of member j 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 m rows and n columns whose entry in row j and column i is 0 when member j works on day i and 1 when member j is on vacation on day i. 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 m and, for each member, through the days in order 1 to n. 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.