#include using namespace std; const long long MOD = 998244353; const long long ONE_TENTH = 299473306; struct unionfind{ vector p; long long ans; vector s; unionfind(int N): p(N, -1), ans(1), s(N, -1){ for (int i = 0; i < N; i++){ ans *= 10; ans %= MOD; } } int root(int x){ if (p[x] == -1){ return x; } else { p[x] = root(p[x]); return p[x]; } } void set(int x, int y){ x = root(x); if (s[x] == -1){ s[x] = y; ans *= ONE_TENTH; ans %= MOD; } else if (s[x] != y){ ans = 0; } } void unite(int x, int y){ x = root(x); y = root(y); if (x != y){ p[x] = y; if (s[x] == -1 || s[y] == -1){ ans *= ONE_TENTH; ans %= MOD; if (s[y] == -1){ s[y] = s[x]; } } else if (s[x] != s[y]){ ans = 0; } } } }; int main(){ int W, H; cin >> W >> H; vector Q(H); for (int i = 0; i < H; i++){ cin >> Q[i]; } unionfind UF(W); for (int i = 0; i < H; i++){ vector p(26, -1); for (int j = 0; j < W; j++){ if (isdigit(Q[i][j]) > 0){ UF.set(j, Q[i][j] - '0'); } else if (isalpha(Q[i][j]) > 0){ int c = Q[i][j] - 'a'; if (p[c] != -1){ UF.unite(p[c], j); } p[c] = j; } } cout << UF.ans << endl; } }