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
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
#include <bits/stdc++.h>
using namespace std;

#define int long long
#define ii pair<int,int>
#define iii tuple<int,int,int>
#define fi first
#define se second
#define endl '\n'

#define pub push_back
#define pob pop_back
#define puf push_front
#define pof pop_front
#define lb lower_bound
#define ub upper_bound

#define rep(x,start,end) for(int x=(start)-((start)>(end));x!=(end)-((start)>(end));((start)<(end)?x++:x--))
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()

mt19937 rng(chrono::system_clock::now().time_since_epoch().count());

const int MOD=998244353;

int n,q;
string s;

struct dat{
	int mat[7][7]={};
	
	int pre[6]={-1,-1,-1,-1,-1,-1};
	int suf[6]={-1,-1,-1,-1,-1,-1};
	int dp[6][6]={};
	int bm;
	
	dat(){}
	
	dat(int s){
		rep(x,0,7) mat[x][x]=mat[s][x]=1;
		
		pre[s]=suf[s]=0;
		dp[s][s]=1;
		bm=1<<s;
	}
};

dat merge(dat A,dat B){
	dat res;
	
	rep(x,0,7) rep(y,0,7) rep(z,0,7){
		res.mat[x][z]=(res.mat[x][z]+A.mat[x][y]*B.mat[y][z])%MOD;
	}
	
	res.bm=A.bm|B.bm;
	
	rep(x,0,6){
		if (A.pre[x]!=-1) res.pre[x]=A.pre[x];
		else res.pre[x]=B.pre[x]|A.bm;
		
		if (B.suf[x]!=-1) res.suf[x]=B.suf[x];
		else res.suf[x]=A.suf[x]|B.bm;
	}
	
	rep(x,0,6) rep(y,0,6){
		if (A.pre[x]==-1) res.dp[x][y]=(res.dp[x][y]+B.dp[x][y])%MOD;
		if (B.pre[y]==-1) res.dp[x][y]=(res.dp[x][y]+A.dp[x][y])%MOD;
	}
	
	rep(b,0,6) rep(c,0,6) if (((B.pre[c]>>b)&1)==0 && ((A.suf[b]>>c)&1)==0){
		rep(a,0,6) rep(d,0,6) res.dp[a][d]=(res.dp[a][d]+A.dp[a][b]*B.dp[c][d])%MOD;
	}
	
	return res;
}

struct node{
	int s,e,m;
	dat val;
	node *l,*r;
	
	node (int _s,int _e){
		s=_s,e=_e,m=s+e>>1;
		
		if (s!=e){
			l=new node(s,m);
			r=new node(m+1,e);
			
			val=merge(l->val,r->val);
		}
		else{
			val=dat(::s[s]-'a');
		}
	}
	
	void update(int i,int k){
		if (s==e) val=dat(k);
		else{
			if (i<=m) l->update(i,k);
			else r->update(i,k);
			val=merge(l->val,r->val);
		}
	}
} *root;

void calc(){
	int ans=0;
	rep(x,0,6) ans=(ans+root->val.mat[x][6])%MOD;
	rep(x,0,6) rep(y,0,6) ans=(ans-root->val.dp[x][y]+MOD)%MOD;
	cout<<ans<<endl;
}

signed main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin.exceptions(ios::badbit | ios::failbit);
	
	cin>>n>>q;
	cin>>s; s="$"+s;
	
	root=new node(1,n);
	calc();
	
	while (q--){
		int a; char c;
		cin>>a>>c;
		
		root->update(a,c-'a');
		
		calc();
	}
}