#include using namespace std; using ll = long long; using Vi = std::vector ; using Vl = vector; using VVi = vector; ll m = 998244353; class UnionFind { Vi par; Vi siz; Vl val; // VVi iv; public : ll ans; UnionFind(int N = 0) { par.resize(N + 10); siz.resize(N + 10); val.assign(N + 10, -1); iota(par.begin(), par.end(), 0); fill(siz.begin(), siz.end(), 0); for (int i = 0; i < N; i ++) { ans *= 10; ans %= m; } for (int i = N; i < N + 10; i ++) { val[i] = i - N; } } void init(int N) { par.resize(N); siz.resize(N); iota(par.begin(), par.end(), 0); fill(siz.begin(), siz.end(), 0); } int root(int v) { if (v == par[v]) { return v; } else { int p = root(par[v]); if (val[p] != val[v] && val[v] != -1 && val[p] != -1) { ans = 0; } else if (val[v] != -1) { val[p] = val[v]; } else { val[v] = val[p]; } return par[v] = root(par[v]); } } bool unit(int a, int b) { a = root(a); b = root(b); if (a == b) { return false; } if (siz[a] < siz[b]) { swap(a, b); } par[b] = a; siz[a] += siz[b]; if (val[a] != val[b] && val[a] != -1 && val[b] != -1) { ans = 0; } else if ((val[a] != -1) != (val[b] != -1)) { int p = (val[a] == -1 ? b : a); int q = a ^ b ^ p; val[q] = val[p]; ans *= ((m * 3 + 1) / 10); ans %= m; } return true; } }; int main () { int Q, N; cin >> N >> Q; UnionFind uu(N); while (Q--) { string s; cin >> s; Vi A[26]; for (int i = 0; i < N; i ++) { char c = s[i]; if ('0' <= c && c <= '9') { uu.unit(i, c - '0' + N); } else if (c != '?') { A[c - 'a'].push_back(i); } } for (auto a : A) { if (a.size() > 1) { for (int i = 0; i < a.size(); i ++) { uu.unit(a[i], a[0]); } } } cout << uu.ans << endl; } }