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
#include <bits/stdc++.h>

#define ll long long
#define fors(u, n, s) for(ll u = (s); u < (n); u++)
#define foru(u, n) fors(u, n, 0)
#define vec vector
#define pb push_back
#define f first
#define s second
#define ir(a, b, x) (((a) <= (x)) && ((x) <= (b)))
#define pint pair<int, int>
#define us unsigned

using namespace std;

const int M = 13;
int m;

const int N = 12;
int n, k;

const int W = M*(1<<(M-1));

// default denum is (1<<(m-1)) 2^(m-1)

int read_value(){
	ll out = 0;
	ll w = (1<<(m-1));
	bool switched = false;

	char c; cin >> c;
	if (c == 'C') out += w;
	else out -= w;
	char c_ = c;

	foru(_i, m-1){
		cin >> c;
		if(c != c_) switched = true;
		c_ = c;

		if(switched) w = (w>>1);
		if (c == 'C') out += w;
		else out -= w;
	}

	return out;
}

const int A = W*N/2;
const int MOD = 1e9+7;

int pos_cnt[2*A+1];
int help_a[2*A+1];
//int help_b[2*A+1];

int pos_cnt_save[2*A+1];

int cnt = 0;

void step(){
	cnt ++;
	int d = (1<<(m-1));
	int w = m*d;

	foru(i, 2*A+1){
		if(i>=w) help_a[i] = pos_cnt[i-w];
		else help_a[i] = 0;
	}

	if(m == 1) {
		foru(i, 2*A+1) {
			pos_cnt[i] = help_a[i] + help_a[2*A-i];
			if(pos_cnt[i] >= MOD) pos_cnt[i] -= MOD;
		}
		return;
	}

	for(int i = 2*A; i>=0; i--){
		if(i>=((m-1)*d-d/2)) pos_cnt[i] = pos_cnt[i-((m-1)*d-d/2)];
		else pos_cnt[i] = 0;
	}

	swap(pos_cnt, help_a);

	foru(j, m-2) {
		const int delta_1 = -d+(d>>(j+2));
		const int delta_2 = -d-(d>>(j+2));

		fors(i, A+1+cnt*W, A-cnt*W){
			pos_cnt[i] += help_a[i];
			if(pos_cnt[i] >= MOD) pos_cnt[i] -= MOD;
		}

		fors(i, min(A+1+cnt*W, 2*A+1+delta_2), A-cnt*W){
			help_a[i] = help_a[i-delta_1]+help_a[i-delta_2];
			if(help_a[i] >= MOD) help_a[i] -= MOD;
		}

		fors(i, min(A+1+cnt*W, 2*A+1+delta_1), min(A+1+cnt*W, 2*A+1+delta_2)){
			help_a[i] += help_a[i-delta_1];
		}

		/*fors(i, A+1+cnt*W,  A-cnt*W){
			help_a[i] = 0;
			if(i-delta_1 <= 2*A) help_a[i] += help_a[i-delta_1];
			if(i-delta_2 <= 2*A) help_a[i] += help_a[i-delta_2];
			if(help_a[i] >= MOD) help_a[i] -= MOD;
		}*/

		
	}

	foru(i, 2*A+1){
		pos_cnt[i] += help_a[i];
		if(pos_cnt[i] >= MOD) pos_cnt[i] -= MOD;
	}

	foru(i, 2*A+1) {
		help_a[i] = pos_cnt[i] + pos_cnt[2*A-i];
		if(help_a[i] >= MOD) help_a[i] -= MOD;
	}
	swap(help_a, pos_cnt);

	//ll sum = 0;
	//foru(i, 2*A+1) sum += pos_cnt[i];
	//cout << "debug " << sum << endl;
}

int main(){
	//ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	
	cin >> n >> m >> k;

	ll tot = 0;
	foru(_i, k) tot += read_value();
	
	if(k == n){
		cout << (tot == 0);
		return 0;
	}

	pos_cnt[A] = 1;

	int cnt = 0;

	while(true){
		int out = 0;
		foru(i, 2*A+1){
			int j = 2*A + tot - i;
			if(!ir(0, 2*A, j)) continue;
			out = (((ll)out) + 1LL*pos_cnt[i]*pos_cnt[j])%MOD;
		}
		cout << out << " ";
		
		cnt ++;
		if(cnt == n-k+1) return 0;

		foru(i, 2*A+1) pos_cnt_save[i] = pos_cnt[i];
		step();

		out = 0;
		foru(i, 2*A+1){
			int j = 2*A + tot - i;
			if(!ir(0, 2*A, j)) continue;
			out = ((ll)out + 1LL*pos_cnt[i]*pos_cnt_save[j])%MOD;
		}
		cout << out << " ";

		cnt ++;
		if(cnt == n-k+1) return 0;
	}

}