import sys
# import numpy as np

mod = 998244353


def inv_mod(a):
    a %= mod
    if a == 0: return 0
    s, t = mod, a
    m0, m1 = 0, 1
    while t:
        u = s // t
        s -= t * u
        m0 -= m1 * u
        s, t = t, s
        m0, m1 = m1, m0
    if m0 < 0: m0 += mod // s
    return m0


def main():
    input = sys.stdin.readline
    n, qn = map(int, input().split())
    uf = [-1] * n
    fixed = [-1] * n
    i10 = inv_mod(10)
    ans = pow(10, n, mod)

    def red10():
        nonlocal ans
        ans *= i10
        ans %= mod

    def find(x):
        nonlocal uf
        y = x
        while uf[x] >= 0: x = uf[x]
        while uf[y] >= 0:
            z = uf[y]
            uf[y] = x
            y = z
        return x

    def union(x, y):
        nonlocal uf, ans, fixed
        x, y = find(x), find(y)
        if x == y: return False
        if uf[x] > uf[y]: x, y = y, x
        uf[x] += uf[y]
        uf[y] = x
        if fixed[x] == -1:
            if fixed[y] == -1:
                red10()
            else:
                fixed[x] = fixed[y]
                red10()
        else:
            if fixed[y] == -1:
                red10()
            else:
                if fixed[x] != fixed[y]:
                    ans = 0
        return True

    zero, nine = ord('0'), ord('9')
    a = ord('a')
    q = ord('?')
    for _ in range(qn):
        S = map(ord, input().rstrip())
        d = [-1] * 26
        for i, s in enumerate(S):
            if s == q:
                continue
            i = find(i)
            if zero <= s <= nine:
                s -= zero
                if fixed[i] == -1:
                    fixed[i] = s
                    red10()
                else:
                    if fixed[i] != s:
                        ans = 0
            else:
                s -= a
                if d[s] != -1:
                    j = d[s]
                    union(i, j)
                else:
                    d[s] = i
            # if _ == 3:
            #     print(ans, end = ' ')
        print(ans)
                            



if __name__ == '__main__':
    main()