1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
#include<bits/stdc++.h>
using namespace std;
using LL=long long;
#define FOR(i,l,r)for(int i=(l);i<=(r);++i)
#define REP(i,n)FOR(i,0,(n)-1)
#define ssize(x)int(x.size())
#ifdef DEBUG
auto&operator<<(auto&o,pair<auto,auto>p){return o<<"("<<p.first<<", "<<p.second<<")";}
auto operator<<(auto&o,auto x)->decltype(x.end(),o){o<<"{";int i=0;for(auto e:x)o<<","+!i++<<e;return o<<"}";}
#define debug(X...)cerr<<"["#X"]: ",[](auto...$){((cerr<<$<<"; "),...)<<endl;}(X)
#else
#define debug(...){}
#endif

constexpr int mod = 1'000'000'007;
int add(int a, int b) {
	a += b;
	return a >= mod ? a - mod : a;
}
void self_add(int &a, int b) {
	a = add(a, b);
}
int sub(int a, int b) {
	return add(a, mod - b);
}
int mul(int a, int b) {
	return int(a * LL(b) % mod);
}
int powi(int a, int b) {
	for(int ret = 1;; b /= 2) {
		if(b == 0)
			return ret;
		if(b & 1)
			ret = mul(ret, a);
		a = mul(a, a);
	}
}
int inv(int x) {
	return powi(x, mod - 2);
}
struct BinomCoeff {
	vector<int> fac, rev;
	BinomCoeff(int n) {
		fac = rev = vector(n + 1, 1);
		FOR(i, 1, n) fac[i] = mul(fac[i - 1], i);
		rev[n] = inv(fac[n]);
		for(int i = n; i > 0; --i)
			rev[i - 1] = mul(rev[i], i);
	}
	int operator()(int n, int k) {
		return mul(fac[n], mul(rev[n - k], rev[k]));
	}
};

int eval(vector<int> t) {
	int m = ssize(t);
	int pot = 1 << (m - 1);
	int score = 0;
	bool changed = false;
	REP (i, m) {
		if (i && t[i - 1] != t[i])
			changed = true;
		if (changed)
			pot /= 2;
		if (t[i])
			score += pot;
		else
			score -= pot;
	}
	return score;
}

void sub_m_1(int n, int pref_score) {
	vector<int> ans(n + 1);
	BinomCoeff bin(n + pref_score);
	REP (i, n + 1) {
		if (((i - pref_score) & 1) || i < pref_score) {
			ans[i] = 0;
			continue;
		}
		int even = pref_score + (i - pref_score) / 2;
		int odd = (i - pref_score) / 2;
		ans[i] = bin(even + odd, odd);
	}
	REP (i, n + 1) {
		if (i)
			cout << ' ';
		cout << ans[i];
	}
	cout << '\n';
}

int main() {
	cin.tie(0)->sync_with_stdio(0);
	int n, m, k;
	cin >> n >> m >> k;
	n -= k;
	int pref_score = 0;
	REP (i, k) {
		vector<int> t;
		REP (j, m) {
			char c;
			cin >> c;
			t.emplace_back(c == 'C');
		}
		pref_score += eval(t);
	}
	pref_score = abs(pref_score);
	if (m == 1) {
		sub_m_1(n, pref_score);
		return 0;
	}
	vector<int> parity(m - 2);
	REP (i, m - 2)
		parity[i] = (pref_score >> i) & 1;
	pref_score >>= (m - 2);

	vector bin(n + 1, vector(n + 1, 0));
	REP (i, n + 1)
		bin[i][0] = bin[i][i] = 1;
	FOR (i, 1, n)
		FOR (j, 1, i - 1)
			bin[i][j] = add(bin[i - 1][j], bin[i - 1][j - 1]);
	const int C = n * 2;
	const int B = n * m * 2;
	vector dp(n + 1, vector(C * 2 + 1, vector(B * 2 + 1, 0)));
	dp[0][C][B] = 1;
	REP (i, m - 2) {
		vector pdp(n + 1, vector(C * 2 + 1, vector(B * 2 + 1, 0)));
		REP (cnt, n + 1) {
			FOR (carry, -C, C) {
				FOR (bottom_sum, -B, B) {
					int val = dp[cnt][carry + C][bottom_sum + B];
					if (!val)
						continue;
					REP (cnt_add, n - cnt + 1) {
						int ncnt = cnt + cnt_add;
						REP (even_cnt_bot, cnt_add + 1) {
							int bot_delta = (1 + i) * (even_cnt_bot * 2 - cnt_add) * 2 - (even_cnt_bot * 2 - cnt_add);
							int nbot = bottom_sum + bot_delta;
							int ways = mul(bin[cnt_add][even_cnt_bot], bin[ncnt][cnt]);
							self_add(pdp[ncnt][carry + C][nbot + B], mul(val, ways));
						}
					}
				}
			}
		}
		vector ndp(n + 1, vector(C * 2 + 1, vector(B * 2 + 1, 0)));
		REP (cnt, n + 1) {
			FOR (carry, -C, C) {
				FOR (bottom_sum, -B, B) {
					int val = pdp[cnt][carry + C][bottom_sum + B];
					if (!val)
						continue;
					REP (even_cnt_cur, cnt + 1) {
						int cur_val = even_cnt_cur * 2 - cnt + carry;
						if ((cur_val & 1) != parity[i])
							continue;
						int ncarry = (cur_val - parity[i]) / 2;
						int ways = bin[cnt][even_cnt_cur];
						self_add(ndp[cnt][ncarry + C][bottom_sum + B], mul(val, ways));
					}
				}
			}
		}
		dp = ndp;
	}

	vector pd(n + 1, vector(B * 2 + 1, 0));
	REP (cnt, n + 1) {
		FOR (carry, -C, C) {
			FOR (bottom_sum, -B, B) {
				int val = dp[cnt][carry + C][bottom_sum + B];
				if (!val)
					continue;
				REP (cnt_add, n - cnt + 1) {
					REP (even_cnt, cnt_add + 1) {
						int delta = (2 * m - 3) * (even_cnt * 2 - cnt_add);
						int ways = mul(bin[cnt_add][even_cnt], bin[cnt + cnt_add][cnt_add]);
						self_add(pd[cnt + cnt_add][carry + bottom_sum + delta + B], mul(val, ways));
					}
				}
			}
		}
	}

	vector<int> ans(n + 1);
	REP (cnt, n + 1) {
		FOR (bottom_sum, -B, B) {
			int val = pd[cnt][bottom_sum + B];
			if (!val)
				continue;
			REP (cnt_add, n - cnt + 1) {
				REP (even_cnt, cnt_add + 1) {
					int delta = 2 * m * (even_cnt * 2 - cnt_add);
					int ways = mul(bin[cnt_add][even_cnt], bin[cnt + cnt_add][cnt_add]);
					if (bottom_sum + delta == pref_score) {
						self_add(ans[cnt + cnt_add], mul(val, ways));
					}
				}
			}
		}
	}

	REP (i, n + 1) {
		if (i)
			cout << ' ';
		cout << ans[i];
	}
	cout << '\n';
}