rt,大概是 Splay 板子的细节问题
//when you use vector or deque,pay attention to the size of it.
//by OldDirverTree
#include<bits/stdc++.h>
#include<bits/extc++.h>
//#include<atcoder/all>
#define P pair<int,int>
#define int long long
#define mid (l+r>>1)
using namespace std;
using namespace __gnu_pbds;
//using namespace atcoder;
const int N=2e5+1,mod=998244353;
int n,m,tot,root;
int read() {
int x=0; bool f=true; char c=0;
while (!isdigit(c) ) f&=(c!='-'),c=getchar();
while (isdigit(c) ) x=(x<<3)+(x<<1)+(c&15),c=getchar();
return f?x:-x;
}
struct Matrix {
int a,b,c,d; friend Matrix operator *(Matrix a,Matrix b)
{ return {(a.a*b.a+a.b*b.c)%mod,(a.a*b.b+a.b*b.d)%mod,(a.c*b.a+a.d*b.c)%mod,(a.c*b.b+a.d*b.d)%mod}; }
}W,E;
struct node {
int s[2],fa,siz; bool tagf,tagr; Matrix a,b,c,d,x,y;
void flip() { if (siz) swap(x,y),swap(a,c),swap(b,d),tagf^=1; }
void reverse() { if (siz) swap(s[0],s[1]),swap(a,b),swap(c,d),tagr^=1; }
}T[N];
void pushup(int rt) {
if (!rt) return;
T[rt].siz=T[T[rt].s[0] ].siz+T[T[rt].s[1] ].siz+1;
T[rt].a=T[T[rt].s[0] ].a*T[rt].x*T[T[rt].s[1] ].a;
T[rt].b=T[T[rt].s[1] ].b*T[rt].x*T[T[rt].s[0] ].b;
T[rt].c=T[T[rt].s[0] ].c*T[rt].y*T[T[rt].s[1] ].c;
T[rt].d=T[T[rt].s[1] ].d*T[rt].y*T[T[rt].s[0] ].d;
}
void pushdown(int rt) {
if (T[rt].tagf) T[T[rt].s[0] ].flip(),T[T[rt].s[1] ].flip(),T[rt].tagf=0;
if (T[rt].tagr) T[T[rt].s[0] ].reverse(),T[T[rt].s[1] ].reverse(),T[rt].tagr=0;
}
void rotate(int x) {
int y=T[x].fa,z=T[y].fa;
bool fx=T[y].s[0]^x,fy=T[z].s[0]^y;
T[y].s[fx]=T[x].s[!fx],T[T[x].s[!fx] ].fa=y;
T[x].s[!fx]=y,T[y].fa=x,T[z].s[fy]=x,T[x].fa=z;
pushup(y),pushup(x);
}
void splay(int x,int rt)
{
while (T[x].fa^rt) {
int y=T[x].fa,z=T[y].fa;
bool fx=T[y].s[0]^x,fy=T[z].s[0]^y;
if (z^rt) rotate(fx^fy?x:y); rotate(x);
}
if (!rt) root=x;
}
int get(int rt,int k) {
pushdown(rt); if (T[T[rt].s[0] ].siz+1==k) return rt;
if (k<=T[T[rt].s[0] ].siz) return get(T[rt].s[0],k);
else return get(T[rt].s[1],k-T[T[rt].s[0] ].siz-1);
}
void insert(bool o) {
tot++,T[tot].siz=1,T[tot].x=o?W:E,T[tot].y=o?E:W; if (tot==1) root=tot;
else { int x=get(root,tot-1); T[tot].fa=x,T[x].s[1]=tot; splay(tot,0); }
}
int split(int l,int r) {
if (l==1&&r==tot) return root;
else if (l==1) { int x=get(root,r+1); splay(x,0); return T[x].s[0]; }
else if (r==tot) { int x=get(root,l-1); splay(x,0); return T[x].s[1]; }
else { int x=get(root,l-1),y=get(root,r+1); splay(x,0),splay(y,x); return T[y].s[0]; }
}
main()
{
cin.tie(0),W={1,1,0,1},E={0,mod-1,1,2};
cin>>n>>m; string s; char o; int l,r;
T[0].a=T[0].b=T[0].c=T[0].d={1,0,0,1};
for (int i=1;i<=n;i++) cin>>o,insert(o=='W');
Matrix ans=W*T[root].a;
printf("%lld %lld",ans.d,ans.b);
while (m--) {
cin>>s; if (s=="APPEND") cin>>o,insert(o=='W');
else if (s=="FLIP") { cin>>l>>r; int x=split(l,r); T[x].flip(),pushup(T[x].fa),pushup(T[T[x].fa].fa); }
else { cin>>l>>r; int x=split(l,r); T[x].reverse(),pushup(T[x].fa),pushup(T[T[x].fa].fa); }
ans=W*T[root].a; printf("\n%lld %lld",ans.d,ans.b);
}
return 0;
}