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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
#include <bits/stdc++.h>
 
#define INF 2147483647
#define LINF 9223372036854775807
#define NINF -2147483648
#define NLINF -9223372036854775808
#define M 1000000007
#define M1 998244353
#define A 26
#define K 31
#define P 2137
 
using namespace std;
using db=double;
using dbl=long double;
using ll=long long;
using pi=pair<int,int>;
using pl=pair<ll,ll>;
using vi=vector<int>;
using vl=vector<ll>;
using gr=vector<vector<int> >;
using grl=vector<vector<ll> >;

 
#define fp(x, a, b) for (int (x) = (a); (x) < (b); (x)++)
#define f(x, n) for (int (x) = 0; (x) < (n); (x)++)
#define fnp(x, a, b) for (int (x) = (b) - 1; (x) >= (a); (x)--)
#define fn(x, n) for (int (x) = (n - 1); (x) >= 0; (x)--)
#define sgn(x) (x) > 0 ? 1 : (x) == 0 ? 0 : -1
#define gcd(a, b) __gcd((a), (b))
#define lcm(a, b) (a) * (b) / gcd((a), (b))
#define x first
#define y second
#define mp make_pair 
#define pb push_back
#define s(x) x.size()
#define all(x) x.begin(), x.end()
#define ans(x) cout<<(x)<<"\n"
#define yes cout<<"YES\n";
#define no cout<<"NO\n";
#define fl cout.flush()
#define debarr(x, n) f(i, (n)){cout<<(x)[i]<<" ";}cout<<"\n"
#define debgr(x, n) f(i, (n)){f(j, s((x)[i])){cout<<(x)[i][j]<<" ";}cout<<"\n";}

 
mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());

class mint
{
	public:
	ll _x, _m;
	ll mintPow(ll _a0, ll _b0){if(_b0 == 0){return (ll)1;}else if((_b0 & 1) == 0){ll _buff = (mintPow(_a0, (_b0 >> 1)) % _m);return (_buff * _buff) % _m;}else{return (_a0 * mintPow(_a0, _b0 - 1)) % _m;}}
	ll mintInv(ll _a0){return mintPow(_a0, _m - 2);}
	ll pow(ll _b0){return mintPow(_x, _b0);}
	ll inv(){return mintInv(_x);}
	mint(){_x = 0;_m = M;}
	mint(ll _x0){_m = M; _x = _x0 % _m;}
	friend ostream& operator<<(ostream& _o, const mint& _x0);
	mint operator=(const mint& _y0){_x = _y0._x;return *this;}
	mint operator^=(const mint& _b0){_x = mintPow(_x, _b0._x);return *this;}
	mint operator+(const mint& _y0){mint _z0 = mint((_x + _y0._x) % _m);return _z0;}
	mint operator+=(const mint& _y0){_x = (_x + _y0._x) % _m;return *this;}
	mint operator-(const mint& _y0){mint _z0 = mint((_x - _y0._x + _m) % _m);return _z0;}
	mint operator-=(const mint& _y0){_x = (_x - _y0._x + _m) % _m;return *this;}
	mint operator*(const mint& _y0){mint _z0 = mint((_x * _y0._x) % _m);return _z0;}
	mint operator*=(const mint& _y0){_x = (_x * _y0._x) % _m;return *this;}
	mint operator/(const mint& _y0){mint _z0 = mint((_x * mintInv(_y0._x)) % _m);return _z0;}
	mint operator/=(const mint& _y0){_x = (_x * mintInv(_y0._x)) % _m;return *this;}
	mint operator%(const mint& _y0){mint _z0 = mint((_x % _y0._x) % _m);return _z0;}
	mint operator%=(const mint& _y0){_x = (_x % _y0._x) % _m;return *this;}
	bool operator==(const mint& _y0){return _x == _y0._x;}
	bool operator!=(const mint& _y0){return _x != _y0._x;}
	bool operator>=(const mint& _y0){return _x >= _y0._x;}
	bool operator<=(const mint& _y0){return _x <= _y0._x;}
	bool operator>(const mint& _y0){return _x > _y0._x;}
	bool operator<(const mint& _y0){return _x < _y0._x;}
	mint operator=(const ll& _y0){_x = _y0;return *this;}
	mint operator^=(const ll& _b0){_x = mintPow(_x, _b0);return *this;}
	mint operator+(const ll& _y0){mint _z0 = mint((_x + _y0) % _m);return _z0;}
	mint operator+=(const ll& _y0){_x = (_x + _y0) % _m;return *this;}
	mint operator-(const ll& _y0){mint _z0 = mint((_x - _y0 + _m) % _m);return _z0;}
	mint operator-=(const ll& _y0){_x = (_x - _y0 + _m) % _m;return *this;}
	mint operator*(const ll& _y0){mint _z0 = mint((_x * _y0) % _m);return _z0;}
	mint operator*=(const ll& _y0){_x = (_x * _y0) % _m;return *this;}
	mint operator/(const ll& _y0){mint _z0 = mint((_x * mintInv(_y0)) % _m);return _z0;}
	mint operator/=(const ll& _y0){_x = (_x * mintInv(_y0)) % _m;return *this;}
	mint operator%(const ll& _y0){mint _z0 = mint((_x % _y0) % _m);return _z0;}
	mint operator%=(const ll& _y0){_x = (_x % _y0) % _m;return *this;}
	bool operator==(const ll& _y0){return _x == _y0;}
	bool operator!=(const ll& _y0){return _x != _y0;}
	bool operator>=(const ll& _y0){return _x >= _y0;}
	bool operator<=(const ll& _y0){return _x <= _y0;}
	bool operator>(const ll& _y0){return _x > _y0;}
	bool operator<(const ll& _y0){return _x < _y0;}
	mint operator[](const ll& _j){return (*this)[_j];}
};
ostream& operator<<(ostream& _o, const mint& _x0){_o << _x0._x;return _o;}

class Fac
{
	public:
	ll _n;
	mint* _a;
	Fac(){}
	Fac(ll _n0)
	{
		_n = _n0 + 1;
		_a = new mint[_n];
		f(i, _n)
		{
			_a[i] = mint();
		}
		_a[0] = 1;
		fp(i, 1, _n)
		{
			_a[i] = _a[i - 1] * i;
		}
	}
	mint operator[](const ll& _i)
	{
		return _a[_i];
	}
};

class Pow
{
	public:
	ll _n, _p;
	mint* _a;
	Pow()
	{}
	Pow(ll _n0, ll _p0)
	{
		_n = _n0 + 1;
		_p = _p0;
		_a = new mint[_n];
		f(i, _n)
		{
			_a[i] = mint();
		}
		_a[0] = 1;
		fp(i, 1, _n)
		{
			_a[i] = _a[i - 1] * _p;
		}
	}
	
	mint operator[](const ll& _i)
	{
		return _a[_i];
	}
};

 
void input();
void compute();
 
int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int T = 1;
	//cin >> T;
	while(T--)
	{
		input();
		compute();
	}
	return 0;
}

#define N 200010
 
int n;
int q;
int g;
mint nCnt;
mint arrSum;
char c;
string s;
int diffOdd;
int diffEven;
mint f[N];
mint fInv[N];
Fac fac;
Pow pow2;
mint _154[N][3];

mint cos(mint x) {
	mint i = 2;
	mint result = 0;
	mint mod = M;
	i = i.inv();
	if(x == 0) {
		result = 1;
		return result;	
	} else if(x == 1) {
		result = i;
		return result;
	} else if(x == 2) {
		result = (mod - i) % M;
		return result;
	} else if(x == 3) {
		result = (M - 1) % M;
		return result;
	} else if(x == 4) {
		result = (mod - i) % M;
		return result;
	} else {
		result = i;
		return result;
	}
}

mint _154Calculate(mint i, mint a) {
	mint result = 0;
	mint i3 = 3;
	mint mod = M;
	i3 = i3.inv();
	fp(j, 1, 4) {
		mint sum = 0;
		if(i % 2 == 1) {
			if(j == 1) {
				sum = 1;
			} else if(j == 2) {
				sum = M - 1;
			} else {
				sum = mod - pow2[i._x];
			}
		} else {
			if(j == 1) {
				sum = 1;
			} else if(j == 2) {
				sum = 1;
			} else {
				sum = pow2[i._x];
			}
		}
		mint d = ((i - a * 2) * j) % 6;
		sum *= cos(d);
		result += sum;
	}
	result *= i3;
	return result;
}

void input()
{
	cin >> n >> q >> s;
}

void compute()
{
	fac = Fac(n + 3);
	pow2 = Pow(n + 3, 2);
	fp(i, 1, n + 3) {
		f[i] = fac[i];
		fInv[i] = fac[i].inv();
		f(j, 3) {
			mint _i = i;
			mint _j = j;
			if(j == 0) {
				_154[i][0] = pow2[i] - _154Calculate(_i, _j);
			} else if (j == 1) {
				_154[i][2] = pow2[i] - _154Calculate(_i, _j);
			} else {
				_154[i][1] = pow2[i] - _154Calculate(_i, _j);
			}
			//cout<<_154[i][j]<<" ";
		}
		//cout<<"\n";
	}
	/*_154[1][0] = 1;
	_154[1][1] = 1;
	_154[1][2] = 2;
	_154[2][0] = 3;
	_154[2][1] = 2;
	_154[2][2] = 3;
	_154[3][0] = 6;
	_154[3][1] = 5;
	_154[3][2] = 5;*/
	_154[0][0] = 0;
	_154[0][1] = 1;
	_154[0][2] = 1;
	_154[1][0] = 1;
	_154[1][1] = 2;
	_154[1][2] = 1;
	_154[2][0] = 3;
	_154[2][1] = 3;
	_154[2][2] = 2;
	_154[3][0] = 6;
	_154[3][1] = 5;
	_154[3][2] = 5;
	diffEven = 0;
	diffOdd = 0;
	nCnt = 0;
	f(i, n) {
		if(i & 1) {
			if(s[i] == 'Z') {
				diffOdd++;
			}
			if(s[i] == 'C') {
				diffEven++;
			}
		} else {
			if(s[i] == 'C') {
				diffOdd++;
			}
			if(s[i] == 'Z') {
				diffEven++;
			}
		}
		if(s[i] == 'N') {
			nCnt += 1;
		} else if(s[i] == 'C') {
			arrSum += 1;
		} else {
			arrSum += 2;
		}
	}
	//cout<<s<<" "<<nCnt<<" "<<arrSum<<" "<<diffOdd<<" "<<diffEven<<"\n";
	//cout<<nCnt._x<<" "<<(arrSum._x + nCnt._x) % 3<<" "<<_154[nCnt._x][(arrSum._x + nCnt._x) % 3]<<"\n";
	cout<<_154[nCnt._x][(arrSum._x + nCnt._x) % 3] - ((n > 1) && (n & 1) && (diffEven == 0)) - ((n > 1) && (n & 1) && diffOdd == 0)<<"\n";
	f(i, q) {
		cin >> g >> c;
		g--;
		if(c != s[g]) {
			if(g & 1) {
				if(c == 'N' && s[g] == 'C') {
					diffEven--;
				} else if(c == 'N' && s[g] == 'Z') {
					diffOdd--;
				} else if(c == 'C' && s[g] == 'Z') {
					diffOdd--;
					diffEven++;
				} else if(c == 'C' && s[g] == 'N') {
					diffEven++;
				} else if(c == 'Z' && s[g] == 'C') {
					diffOdd++;
					diffEven--;
				} else if(c == 'Z' && s[g] == 'N') {
					diffOdd++;
				}
			} else {
				
				if(c == 'N' && s[g] == 'C') {
					diffOdd--;
				} else if(c == 'N' && s[g] == 'Z') {
					diffEven--;
				} else if(c == 'C' && s[g] == 'Z') {
					diffOdd++;
					diffEven--;
				} else if(c == 'C' && s[g] == 'N') {
					diffOdd++;
				} else if(c == 'Z' && s[g] == 'C') {
					diffOdd--;
					diffEven++;
				} else if(c == 'Z' && s[g] == 'N') {
					diffEven++;
				}
			}
			if(s[g] == 'C') {
				if(c == 'Z') {
					arrSum += 1;
				} else {
					nCnt += 1;
					arrSum -= 1;
				}
			} else if(s[g] == 'Z') {
				if(c == 'C') {
					arrSum -= 1;
				} else {
					arrSum -= 2;
					nCnt += 1;
				}
			} else {
				if(c == 'C') {
					nCnt -= 1;
					arrSum += 1;
				} else {
					arrSum += 2;
					nCnt -= 1;
				}
			}
		}
		s[g] = c;
		//cout<<s<<" "<<nCnt<<" "<<arrSum<<" "<<diffOdd<<" "<<diffEven<<"\n";
		//cout<<nCnt._x<<" "<<(arrSum._x + nCnt._x) % 3<<" "<<_154[nCnt._x][(arrSum._x + nCnt._x) % 3]<<"info\n";
		cout<<_154[nCnt._x][(arrSum._x + nCnt._x) % 3] - ((n > 1) && (n & 1) && (diffEven == 0)) - ((n > 1) && (n & 1) && diffOdd == 0)<<"\n";
	}
}