1 #include<bits/stdc++.h>
2 using namespace std;
3 const int N=110,M=200010,mod=1000003;
4 int n,m,fac[M],deg[N],a[N][N];
5 int pw(int x,int y){
6 int re=1;
7 for(;y;y>>=1,x=1ll*x*x%mod){
8 if(y&1)re=1ll*re*x%mod;
9 }
10 return re;
11 }
12 int gauss(){
13 int fg=0,re=1;
14 for(int i=1;i<n;++i){
15 int pos=i;
16 for(int j=i;j<n;++j)if(a[j][i]){
17 pos=j;break;
18 }
19 if(pos!=i){
20 fg^=1;
21 for(int j=i;j<n;++j)swap(a[i][j],a[pos][j]);
22 }
23 re=1ll*re*a[i][i]%mod;
24 int tmp = pw(a[i][i],mod-2);
25 for(int j=i;j<n;j++)a[i][j]=1ll*a[i][j]*tmp%mod;
26 for(int j=i+1;j<n;++j)
27 for(int k=n-1;k>=i;--k)a[j][k]=(a[j][k]-1ll*a[j][i]*a[i][k]%mod+mod)%mod;
28 }
29 if(fg)re=mod-re;
30 return (re+mod)%mod;
31 }
32 int main(){
33 freopen("bzoj3659.in","r",stdin);
34 freopen("bzoj3659.out","w",stdout);
35 for(int i=fac[0]=1;i<=2e5;++i)fac[i]=1ll*fac[i-1]*i%mod;
36 while(~scanf("%d",&n)&&n){
37 for(int i=1;i<=n;++i){
38 for(int j=1;j<=n;++j)a[i][j]=0;
39 }
40 for(int i=1,s;i<=n;++i){
41 scanf("%d",&s);
42 deg[i]=s;
43 for(int j=1,x;j<=s;++j){
44 scanf("%d",&x);
45 if(i!=x)a[i][x]--,a[i][i]++;
46 }
47 }
48 if(n==1){printf("%d\n",fac[deg[1]]);continue;}
49 int ans = gauss();
50 for(int i=1;i<=n;++i)ans=1ll*ans*fac[deg[i]-1]%mod;
51 ans = 1ll * deg[1] * ans %mod;
52 printf("%d\n",ans);
53 }
54 return 0;
55 }