#include #include #include #include #include #include #include #include #include #include #include #include using namespace std; typedef long long ll; typedef long double ld; typedef pair PII; #define pb push_back #define fi first #define se second //typedef long long vlong; // #define MOD 1000000000 class vlong { public: vector buf; bool jenula(); vlong operator=(int b); vlong operator+=(vlong &b); void print(); }; vlong vlong::operator=(int b) { buf.clear(); buf.pb(b); return *this; } vlong vlong::operator+=(vlong &b) { int r, c1, c2, c3; r = 0; for(int i = 0; i < max(buf.size(), b.buf.size()); i++) { if(i < buf.size()) c1 = buf[i]; else c1 = 0; if(i < b.buf.size()) c2 = b.buf[i]; else c2 = 0; c3 = (c1+c2+r)%MOD; r = (c1+c2+r)/MOD; if(i < buf.size()) buf[i]=c3; else buf.push_back(c3); } if(r>0) buf.push_back(r); return *this; } bool vlong::jenula() { return (buf.size()==0) || (buf.size()==1 && buf[0]==0); } void vlong::print() { printf("%d", buf[buf.size()-1]); for(int i = (int)buf.size()-2; i>=0; i--) printf("%09d", buf[i]); printf("\n"); } struct Vrchol { vector next; map cesty; int co; }; int main() { /* vlong a; a = 1; for(int i = 0; i < 300; i++) a+=a; a.print(); return 0;*/ while(1) { Vrchol v[1010]; int N, L, B, F; scanf("%d %d %d %d", &N, &L, &B, &F); if(N==0) break; int a, b; for(int i = 0; i < N; i++) v[i].co = 0; for(int i = 0; i < N; i++) { scanf("%d %d", &a, &b); for(int j = 0; j < b; j++) { scanf("%d", &a); v[i].next.pb(a-1); v[a-1].co++; } } /*if(L > N){ printf("impossible 1\n"); continue; }*/ /* for(int i = 0; i < N; i++) for(int j = 0; j < 1010; j++) mat[i][j]=0;*/ queue fr; for(int i = 0; i < B; i++) { scanf("%d", &a); // mat[a-1][1] = 1; v[a-1].cesty[1]=1; fr.push(a-1); } int x; while(!fr.empty()) { x = fr.front(); fr.pop(); // printf("fr %d\n", x); for(int i = 0; i < v[x].next.size(); i++) { /*for(int j = 0; j < 1009; j++) { mat[v[x].next[i]][j+1]+=mat[x][j]; }*/ for(map::iterator it = v[x].cesty.begin(); it != v[x].cesty.end(); it++) { if(v[v[x].next[i]].cesty.count((*it).first+1)>0) v[v[x].next[i]].cesty[(*it).first+1]+=(*it).second; else v[v[x].next[i]].cesty[(*it).first+1]=(*it).second; } v[v[x].next[i]].co--; if(v[v[x].next[i]].co==0) fr.push(v[x].next[i]); } } vlong sum; for(int i = 0; i < F; i++) { scanf("%d", &a); if(v[a-1].cesty.count(L)>0) sum+=v[a-1].cesty[L]; } if(sum.jenula()) printf("impossible\n"); else // printf("%Ld\n", sum); sum.print(); } return 0; }