local UF = {} UF.create = function(self, n) self.parent = {} for i = 1, n do self.parent[i] = i end self.gc = n - 10 self.broken = false end UF.getroot = function(self, idx) local parent = self.parent local idx_update = idx while parent[idx] ~= idx do idx = parent[idx] end while parent[idx_update] ~= idx do parent[idx_update], idx_update = idx, parent[idx_update] end return idx end UF.unite = function(self, a, b) local ra = self:getroot(a) local rb = self:getroot(b) local n = #self.parent if ra ~= rb then if ra < rb then self.parent[a], self.parent[ra] = rb, rb if n - 10 < ra then self.broken = true end else self.parent[b], self.parent[rb] = ra, ra if n - 10 < rb then self.broken = true end end self.gc = self.gc - 1 end end UF.new = function(n) local obj = {} setmetatable(obj, {__index = UF}) obj:create(n) return obj end local p10 = {1} for i = 2, 200010 do p10[i] = (p10[i - 1] * 10) % 998244353 end local n, q = io.read("*n", "*n", "*l") local uf = UF.new(n + 10) local t = {} for iq = 1, q do local s = io.read() for i = 1, 26 do t[i] = {} end for i = 1, n do local b = s:byte(i) if b <= 57 then b = b - 48 + 1 uf:unite(i, n + b) elseif b ~= 63 then b = b - 96 table.insert(t[b], i) end end for i = 1, 26 do if 1 < #t[i] then local r = uf:getroot(t[i][1]) for j = 2, #t[i] do uf:unite(r, t[i][j]) end end end if uf.broken then print(0) else print(p10[uf.gc + 1]) end end