from sys import stdin class UnionFind(): def __init__(self, n): self.siz = n - 10 self.parent_or_size = [-1] * n 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: return if 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 for i in range(10): for j in range(i + 1, 10): if uf.same(i + W, j + W): is_zero = 1 print(0 if is_zero else pow10[uf.siz])