mod=998244353 fac=[1] for i in range(1,100): fac.append(fac[-1]*i%mod) finv=[] for i in range(100): finv.append(pow(fac[i],mod-2,mod)) n=int(input()) s=[] for i in range(n): s.append(list(map(lambda x:int(x)-1,input().split()))) S=[0] for si in s: nS=[] for i in S: for j in si: nS.append(i+(1<<(5*j))) nS.sort() S=[] last=-1 for i in nS: if i!=last: S.append(i) last=i ans=0 for bit in S: res=fac[n] for j in range(9): x=bit&31 res*=finv[x] res%=mod bit>>=5 ans+=res print(ans%mod)