#include #include using mint = atcoder::modint998244353; using namespace std; int main() { int w, h; cin >> w >> h; atcoder::dsu uf(w); vector a(w, -1); bool ok = true; while (h--){ string s; cin >> s; for (int i = 0; i < w; i++){ if (isdigit(s[i])){ if (a[i] != -1 and a[i] != (s[i] - '0')){ ok = false; break; } a[i] = s[i] - '0'; } } if (!ok){ cout << 0 << endl; continue; } for (int k = 0; k < 26; k++){ set t; for (int i = 0; i < w; i++){ if (s[i] == (char)('a' + k)){ t.insert(i); } } vector l(t.begin(), t.end()); for (int i = 0; i < max(0, (int)l.size() - 1); i++){ uf.merge(l[i], l[i + 1]); } } mint ans = 1; auto g = uf.groups(); for (auto t : g){ set p; for (int i = 0; i < (int)t.size(); i++){ if (a[t[i]] != -1){ p.insert(a[t[i]]); } } if (p.size() > 1){ ok = false; } if (p.size() == 0){ ans *= 10; } } if (!ok){ cout << 0 << endl; continue; } cout << ans.val() << endl; } }