#ifndef LOCAL #include using namespace std; #define debug(...) (void(0)) #else #include "algo/debug.h" #endif #include #include using mint = atcoder::modint998244353; void solve() { int W, H; cin >> W >> H; atcoder::dsu uf(W); vector ans(W, -1); bool Zero = false; for(int i = 0; i < H; i++) { array leader{}; for(int j = 0; j < 26; j++) leader[j] = -1; string Q; cin >> Q; for(unsigned j = 0; j < Q.size(); j++) if(Q[j] != '?') { if(isdigit(Q[j])) { if(ans[j] != -1 && ans[j] != Q[j] - '0') { Zero = true; }else { ans[j] = Q[j] - '0'; } }else { int a = Q[j] - 'a'; if(leader[a] != -1) { if(!uf.same(leader[a], j)) { uf.merge(leader[a], j); } }else { leader[a] = j; } } } auto grs = uf.groups(); int cc = 0; for(auto&&gr: grs) { int val = -1; for(int v : gr) if(ans[v] != -1) { if(val == -1) val = ans[v]; else if(val != ans[v])Zero = true; } if(val != -1) { for(int v: gr) { ans[v] = val; } }else { cc++; } } debug(ans); cout << (Zero ? 0 : mint(10).pow(cc).val()) << endl; } } int main() { std::ios::sync_with_stdio(false); std::cin.tie(nullptr); int tt = 1; // std::cin >> tt; while(tt--) { solve(); } }