class UnionFind: def __init__(self, n): self.data = [-1] * (n + 1) self.nexts = [-1] * (n + 1) # 次の要素(なければ-1) self.tails = list(range(n + 1)) # 末尾の要素 def root(self, a: int) -> int: if self.data[a] < 0: return a self.data[a] = self.root(self.data[a]) return self.data[a] def unite(self, a: int, b: int) -> bool: pa = self.root(a) pb = self.root(b) if pa == pb: return False if self.data[pa] > self.data[pb]: pa, pb = pb, pa self.data[pa] += self.data[pb] # pa を pb をつなげる self.data[pb] = pa # pa の末尾に pb を繋げる self.nexts[self.tails[pa]] = pb self.tails[pa] = self.tails[pb] return True def issame(self, a: int, b: int) -> bool: return self.root(a) == self.root(b) def size(self, a: int) -> int: """a が属する集合のサイズ""" return -self.data[self.root(a)] def group(self, a): """a が属する集合""" v = self.root(a) while v != -1: yield v v = self.nexts[v] def query(ind): for i in range(10): if uf.issame(ind, W+i): return i return -1 # 未確定 MOD = 998244353 W, H = map(int, input().split()) uf = UnionFind(W + 10) isinvalid = False for _ in range(H): S = input() if isinvalid: print(0) continue al = [-1] * 255 for i, c in enumerate(S): if c == '?': continue if c.isdigit(): x = query(i) if x != -1 and x != int(c): isinvalid = True break uf.unite(i, W+int(c)) elif c.isalpha(): p = ord(c) if al[p] != -1: x = query(i) y = query(al[p]) if x != -1 and y != -1 and x != y: isinvalid = True break uf.unite(i, al[p]) al[p] = i if isinvalid: print(0) continue res = 1 used = set() for i in range(W): if query(i) == -1: r = uf.root(i) if r not in used: res *= 10 res %= MOD used.add(r) print(res)