Some government projects are carried out not by government offices themselves but by private companies chosen through a public tender. Before the selection begins, every candidate company sends in a letter containing its offer, and a committee picks the best offer based on its price and quality.
That is the theory. In practice, the outcome is often decided in advance by a bribe paid to the committee, and fake candidate companies are added to the process to disguise the fraud. To make it look genuine, the offer letters from these fake companies must also appear to have been received. Because this happens so often, someone built a program that automatically assembles a letter from a fixed list of pre-defined sentences under the following rules:
Help us detect these fake letters. Given the rules of the generator, compute how many different valid letters can be assembled.
The input consists of several scenarios. Each scenario begins with a line containing four positive integers N, L, B, F:
The next N lines describe the successor rules. Each line starts with a sentence number $i$, an integer $D_i$ ($0 \le D_i \le 1000$), and then $D_i$ sentence numbers listing the sentences that may immediately follow sentence $i$.
The following B lines each contain the number of a possible starting (greeting) sentence, and the last F lines each contain the number of a possible final (closing) sentence.
The list of scenarios ends with a line containing four zeros, which is not processed.
The generator itself never checks whether a sentence repeats; this is always guaranteed by the successor rules. You may therefore assume that, when the rules are followed, no letter ever contains the same sentence twice, a greeting can appear only at the beginning, and a closing can appear only at the end.
For each scenario, print a single line with the total number of valid letters that have exactly L sentences. This number can be very large and may exceed $2^{32}$. If no valid letter of the required length exists, print the word impossible instead.