Letter Lies

No attempts yetTime limit3sMemory limit128 MB

Problem

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:

  • Some sentences are greetings and may appear only at the very beginning; every letter must start with a greeting.
  • Some sentences are closings and may appear only at the very end; every letter must end with a closing.
  • No sentence may appear more than once in the same letter.
  • Each sentence has a successor list restricting which other sentences may immediately follow it. For example, a sentence that says “Hello” cannot be followed by “This concludes our offer”.
  • The letter must have a required length: the exact number of sentences is specified.

Help us detect these fake letters. Given the rules of the generator, compute how many different valid letters can be assembled.

Input

The input consists of several scenarios. Each scenario begins with a line containing four positive integers N, L, B, F:

  • N ($1 \le N \le 1000$) is the total number of sentences;
  • L ($1 \le L \le 1000000$) is the required length (number of sentences) of the letter;
  • B ($1 \le B \le 1000$) is the number of greeting sentences;
  • F ($1 \le F \le 1000$) is the number of closing sentences.

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.

Output

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.