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
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
#include <bits/stdc++.h>
#define MP make_pair
#define PB push_back
#define int long long
#define st first
#define nd second
#define rd third
#define FOR(i, a, b) for(int i =(a); i <=(b); ++i)
#define RE(i, n) FOR(i, 1, n)
#define FORD(i, a, b) for(int i = (a); i >= (b); --i)
#define REP(i, n) for(int i = 0;i <(n); ++i)
#define VAR(v, i) __typeof(i) v=(i)
#define FORE(i, c) for(VAR(i, (c).begin()); i != (c).end(); ++i)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define __builtin_ctz __builtin_ctzll
#define __builtin_clz __builtin_clzll
#define __builtin_popcount __builtin_popcountll
using namespace std;
template<typename TH> void _dbg(const char* sdbg, TH h) { cerr<<sdbg<<"="<<h<<"\n"; }
template<typename TH, typename... TA> void _dbg(const char* sdbg, TH h, TA... t) {
  while(*sdbg != ',') { cerr<<*sdbg++; } cerr<<"="<<h<<","; _dbg(sdbg+1, t...);
}
#ifdef LOCAL
#define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#define debugv(x) {{cerr <<#x <<" = "; FORE(itt, (x)) cerr <<*itt <<", "; cerr <<"\n"; }}
#else
#define debug(...) (__VA_ARGS__)
#define debugv(x)
#define cerr if(0)cout
#endif
#define next ____next
#define prev ____prev
#define left ____left
#define hash ____hash
typedef long long ll;
typedef long double LD;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VLL;
typedef vector<pair<int, int> > VPII;
typedef vector<pair<ll, ll> > VPLL;

template<class C> void mini(C&a4, C b4){a4=min(a4, b4); }
template<class C> void maxi(C&a4, C b4){a4=max(a4, b4); }
template<class T1, class T2>
ostream& operator<< (ostream &out, pair<T1, T2> pair) { return out << "(" << pair.first << ", " << pair.second << ")";}
template<class A, class B, class C> struct Triple { A first; B second; C third;
  bool operator<(const Triple& t) const { if (st != t.st) return st < t.st; if (nd != t.nd) return nd < t.nd; return rd < t.rd; } };
template<class T> void ResizeVec(T&, vector<int>) {}
template<class T> void ResizeVec(vector<T>& vec, vector<int> sz) {
  vec.resize(sz[0]); sz.erase(sz.begin()); if (sz.empty()) { return; }
  for (T& v : vec) { ResizeVec(v, sz); }
}
typedef Triple<int, int, int> TIII;
template<class A, class B, class C>
ostream& operator<< (ostream &out, Triple<A, B, C> t) { return out << "(" << t.st << ", " << t.nd << ", " << t.rd << ")"; }
template<class T> ostream& operator<<(ostream& out, vector<T> vec) { out<<"("; for (auto& v: vec) out<<v<<", "; return out<<")"; }
template<class T> ostream& operator<<(ostream& out, set<T> vec) { out<<"("; for (auto& v: vec) out<<v<<", "; return out<<")"; }
template<class L, class R> ostream& operator<<(ostream& out, map<L, R> vec) { out<<"("; for (auto& v: vec) out<<v<<", "; return out<<")"; }

const int M = 26;
const int N = 34;
const int P = 1e9 + 7;
int32_t dp[M][4 * M * N][2 * N][N];
int Eval(VI& v, int m) {
  int val = 1 << (m - 1);
  int res = 0;
  int change = 0;
  for (auto ziom : v) {
    if (ziom != v[0]) {
      change = 1;
    }
    if (change) {
      val /= 2;
    }
    if (ziom == 1) {
      res += val;
    } else {
      res -= val;
    }
  }
  //debug(v, res);
  return res;
}
int spow(int a, int b) {
  int r = 1;
  while (b) {
    if (b % 2) {
      r = r * a % P;
    }
    a = a * a % P;
    b /= 2;
  }
  return r;
}
int Inv(int a) { return spow(a, P - 2); }
int newt[N][N];
int fac[N];
int inv[N];
int32_t main() {

  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(10);
  cerr << fixed << setprecision(10);
  cin.tie(0);
  //double beg_clock = 1.0 * clock() / CLOCKS_PER_SEC;
  
  REP (i, N) {
    newt[i][0] = newt[i][i] = 1;
    RE (j, i - 1) {
      newt[i][j] = (newt[i - 1][j] + newt[i - 1][j - 1]) % P;
    }
    inv[i] = Inv(i);
  }
  fac[0] = 1;
  RE (i, N - 1) {
    fac[i] = i * fac[i - 1] % P;
  }
  int n, m, k;
  cin>>n>>m>>k;
  int shift = 0;
  RE (i, k) {
    string s;
    cin>>s;
    VI v(m);
    REP (j, m) {
      if (s[j] == 'C') {
        v[j] = 1;
      }
    }
    shift += Eval(v, m);
  }
  debug(shift);
  if (k == n) {
    cout<<(shift == 0)<<endl;
    return 0;
  }
  if (m == 1) {
    FOR (doloz, 0, n - k) {
      int nn = doloz + k;
      if (nn % 2) {
        cout<<0<<" ";
      } else {
        int need = (nn - k - shift) / 2;
        if (need < 0) {
          cout<<0<<" ";
        } else {
          cout<<newt[nn - k][need]<<" ";
        }
      }
    }
    cout<<endl;
    return 0;
  }
//   if (n <= 8 && m <= 8) {
//     VI evals;
//     VI v(m);
//     REP (mask, 1 << m) {
//       REP (bit, m) {
//         if (mask & (1 << bit)) {
//           v[bit] = 1;
//         } else {
//           v[bit] = 0;
//         }
//       }
//       evals.PB(Eval(v, m));
//     }
//     //debug(evals);
//     int R = m * n * (1ll << (m - 1)) + 20;
//     VI plecak(2 * R);
//     plecak[R + shift] = 1;
//     cout<<plecak[R]<<" ";
//     REP (turn, n - k) {
//       VI nplecak(2 * R);
//       REP (j, 2 * R) {
//         if (plecak[j]) {
//           for (auto e : evals) {
//             nplecak[e + j] += plecak[j];
//             if (nplecak[e + j] >= P) {
//               nplecak[e + j] -= P;
//             }
//           }
//         }
//       }
//       plecak = nplecak;
//       cout<<plecak[R]<<" ";
//     }
//     cout<<endl;
//     return 0;
//   }
  
  shift = abs(shift);
  int flor = shift >> (m - 2);
  VI bicik(m - 2);
  REP (bit, m - 2) {
    if (shift & (1 << bit)) {
      bicik[bit] = 1;
    }
  }
  debug(flor, bicik);
  int B = 2 * M * N;
  dp[2][B][N][0] = 1;
  REP (turn, n - k + 1) {
    // dp[stosy][height][bilans_integral][bilans_lsb][blok]
    FOR (h, 2, m) {
      int bit = 0;
      if (h < m) {
        //bit = bicik[m - 1 - h];
        bit = bicik[h - 2];
      }
      int bil1_dev = 2 * h * turn;
      FOR (bil1, B - bil1_dev, B + bil1_dev) {
        FOR (fake_bil2, 0, 2 * N - 1) {
          {
            int bil2 = fake_bil2 - N;
            if (h < m && (bit + bil2 + turn) % 2 == 0) {
              int sum = 0;
              FOR (blok, 0, turn) {
                sum = (sum + dp[h][bil1][fake_bil2][blok]);
              }
              sum %= P;
              if (sum) {
                FOR (zap, 0, turn) {
                  int nbil = (bit - turn + 2 * zap + bil2) / 2;
                  auto& out = dp[h + 1][bil1][nbil + N][0];
                  out = (out + newt[turn][zap] * sum) % P;
                }
              }
              // rozwaz przejscie do gory
            }
          }
        }
      }
    }
    int res = 0;
    FOR (fake_bil1, 0, 4 * M * N - 1) {
      int bil1 = fake_bil1 - B;
      FOR (fake_bil2, 0, 2 * N - 1) {
        int bil2 = fake_bil2 - N;
        if (bil1 + flor + bil2 == 0) {
          FOR (blok, 0, turn) {
            //             if (dp[t][m][fake_bil1][fake_bil2][blok]) {
            //               debug(bil1, bil2, blok, dp[t][m][fake_bil1][fake_bil2][blok]);
            //             }
            res = (res + dp[m][fake_bil1][fake_bil2][blok]) % P;
          }
        }
      }
    }
    cout<<res * fac[turn] % P<<" ";
    
    if (turn != n - k) {
      FOR (h, 2, m) {
        FORD (blok, turn, 0) {
          int bil1_dev = 2 * h * turn;
          FOR (bil1, B - bil1_dev, B + bil1_dev) {
            FOR (fake_bil2, 0, 2 * N - 1) {
              if (dp[h][bil1][fake_bil2][blok] == 0) { continue; }
              for (int sign = -1; sign <= 1; sign += 2) {
                auto& out = dp[h][bil1 + sign * (2 * h - 3)][fake_bil2][blok + 1];
                out = (out + inv[blok + 1] * dp[h][bil1][fake_bil2][blok]) % P;
              }
              if (h == m) {
                for (int sign = -1; sign <= 1; sign += 2) {
                  auto& out = dp[h][bil1 + sign * 2 * h][fake_bil2][blok + 1];
                  out = (out + inv[blok + 1] * dp[h][bil1][fake_bil2][blok]) % P;
                }
              }
              dp[h][bil1][fake_bil2][blok] = 0;
            }
          }
        }
      }
    }
  }
  cout<<endl;
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  return 0;
}