#include using namespace std; typedef long long ll; const ll mod = 998244353; ll t = 1,n,m,k,q,l,r,b,c,u,v,x,y,z,id[200009],a[200009],nm[200009],vis[200009]; string s; vector to[29]; struct st{ll x,y; /*bool operator < (const st &a) const{return x < a.x;};*/}; bool cmp(const st &a,const st &b){return a.x < b.x;} inline ll read(){ ll s = 0,w = 1; char ch = getchar(); while (ch > '9' || ch < '0'){ if (ch == '-') w = -1; ch = getchar();} while (ch <= '9' && ch >= '0') s = (s << 1) + (s << 3) + (ch ^ 48),ch = getchar(); return s * w; } ll qp(ll x,ll y){ ll a = 1,b = x; while (y){ if (y & 1) a = a * b % mod; b = b * b % mod,y >>= 1; } return a; } ll find(ll x){return x == id[x] ? x : id[x] = find(id[x]);} int main(){//t = read(); n = read(),t = read(); for (ll i = 1;i <= n;i += 1) a[i] = -1,id[i] = i; bool fl = 1; while (t --){ cin>>s,s = ' ' + s; if (!fl){puts("0"); continue;} for (ll i = 0;i < 26;i += 1) to[i].clear(); for (ll i = 1;i <= n;i += 1) nm[i] = -1; ll ans = 1; for (ll i = 1;i <= n;i += 1){ if (s[i] == '?') continue; if (s[i] <= '9' && s[i] >= '0'){ if (a[i] != -1 && a[i] != s[i] - '0'){fl = 0; break;} a[i] = s[i] - '0'; } else to[s[i] - 'a'].emplace_back(i); } if (!fl){puts("0"); continue;} for (ll i = 0;i < 26;i += 1){ for (ll j = 0;j + 1 < to[i].size();j += 1) id[find(to[i][j])] = find(to[i][j + 1]); } for (ll i = 1;i <= n;i += 1) if (a[i] != -1) nm[find(i)] = a[i]; for (ll i = 1;i <= n;i += 1){ ll qwq = find(i); if (a[i] == -1) continue; if (nm[i] != -1 && nm[i] != a[i]){fl = 0; break;} nm[i] = a[i]; } if (!fl){puts("0"); continue;} for (ll i = 1;i <= n;i += 1) vis[i] = 0; ans = 1; for (ll i = 1;i <= n;i += 1) if (!vis[find(i)] && nm[find(i)] == -1) ans = ans * 10 % mod,nm[find(i)] = 1; printf("%lld\n",ans); } return 0; }