#include <cstdio>
#include <cstring>
#define FOR(i,a,b) for(int i=a;i<=b;++i)
#define CP(v,w) memcpy((v),(w),sizeof((w)))
#define max(a,b) (a > b ? a : b)
#define IN "cowfood.in"
#define OUT "cowfood.out"
#define mod 3210121
int Sp[32][32],A[32][1<<14],V[32][32],K,S,N;
void scan()
{
freopen(IN,"r",stdin);
freopen(OUT,"w",stdout);
scanf("%d%d%d",&K,&S,&N);
FOR(i,1,N)
FOR(j,1,K)
scanf("%d",&V[i][j]);
}
int back(int poz,int cfg)
{
if(poz == N+1)
{
int nr(0),total = S;
FOR(i,1,K)
total -= Sp[poz][i],nr += (bool)(cfg & (1<<i));
return total < 0 ? 0 : A[K][total] * (nr & 1 ? -1 : 1);
}
CP(Sp[poz+1],Sp[poz]);
int rez = back(poz+1,cfg);
FOR(i,1,K) Sp[poz+1][i] = max(Sp[poz][i],V[poz][i]);
rez += back(poz+1,cfg | (1<<poz));
return rez % mod;
}
void solve()
{
FOR(i,0,K) A[i][0] = 1;
FOR(j,0,S) A[0][j] = 1;
FOR(i,1,K)
FOR(j,1,S)
A[i][j] = (A[i-1][j] + A[i][j-1]) % mod;
int rez = back(1,0) - (K * S + 1);
printf("%d\n",rez < 0 ? rez + mod : rez);
}
int main()
{
scan();
solve();
return 0;
}