from sys import stdin class UnionFind(): def __init__(self, n): self.siz = n - 10 self.parent_or_size = [-1] * n self.is_zero = False def leader(self, x): if self.parent_or_size[x] < 0: return x self.parent_or_size[x] = self.leader(self.parent_or_size[x]) return self.parent_or_size[x] def same(self, x, y): return self.leader(x) == self.leader(y) def merge(self, x, y): rx, ry = self.leader(x), self.leader(y) if rx < ry: rx, ry = ry, rx if rx == ry: return if ry >= len(self.parent_or_size) - 10: self.is_zero = True elif rx < len(self.parent_or_size) - 10 & self.parent_or_size[rx] > self.parent_or_size[ry]: rx, ry = ry, rx self.parent_or_size[rx] += self.parent_or_size[ry] self.parent_or_size[ry] = rx self.siz -= 1 return W, H = map(int, input().split()) uf = UnionFind(W + 10) is_zero = 0 pow10 = [0] * (W + 1) pow10[0] = 1 for i in range(W): pow10[i + 1] = (pow10[i] * 10) % 998244353 for _ in range(H): if is_zero == 1: print(0) continue s = stdin.readline() pos = [-1] * 26 for i in range(W): if s[i] == '?': continue if '0' <= s[i] and s[i] <= '9': uf.merge(ord(s[i]) - ord('0') + W, i) continue c = ord(s[i]) - ord('a') if pos[c] != -1: uf.merge(i, pos[c]) pos[c] = i print(0 if uf.is_zero else pow10[uf.siz])