1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
//fast
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;

#define all(x) x.begin(),x.end()
#define rep(n) for (int i = 0 ; i<n ; i++)
#define pb push_back

ll podst = 7;
ll mod = 998244353;
unordered_map<ll,ll> xd;

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
	int n,q;
	cin >> n >> q;
	char s[n];
	rep(n) cin >> s[i];
	q++;
	int x = -1;
	char y = 'a';
	while (q--){
		if (x!=-1){
			s[x-1] = y;
		}
		xd.clear();
		for (int i = 0 ; i<(1<<n) ; i++){
			string pod;
			for (int j = 0 ; j<n ; j++){
				if ((1<<j)&i) pod+=s[j];
			}
			ll mn = 1;
			ll a = 0;
			for (auto c : pod){
				a+=ll(c-'a'+1)*mn;
				mn*=podst;
			}
			if (a!=0) xd[a]++;
		}
		ll w = 0;
		for (auto i : xd){
			if (i.second>=2) w++;
		}
		cout << w%mod << '\n';
		if (q!=0) cin >> x >> y;
	}
}