#include <bits/stdc++.h>
using namespace std;
//#pragma GCC optimize("O3")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#define int long long
#define fast ios::sync_with_stdio(false); cin.tie(nullptr);
const int M = 998244353;
const int G = 3;
const int N = 2000005;
unsigned int p[N];
unsigned int f[N];
unsigned int v[N];
unsigned int pwr(unsigned int a, unsigned int b) {
unsigned int r = 1;
a %= M;
while (b > 0) {
if (b % 2 == 1) r = 1ULL * r * a % M;
a = 1ULL * a * a % M;
b /= 2;
}
return r;
}
unsigned int inv(unsigned int a) {
return pwr(a, M - 2);
}
void pre() {
f[0] = 1;
v[0] = 1;
for (int i = 1; i < N; i++) f[i] = 1ULL * f[i - 1] * i % M;
v[N - 1] = inv(f[N - 1]);
for (int i = N - 2; i >= 1; i--) v[i] = 1ULL * v[i + 1] * (i + 1) % M;
}
void Ntt(vector<unsigned int>& a, bool b) {
int n = a.size();
for (int i = 1, j = 0; i < n; i++) {
int k = n >> 1;
for (; j & k; k >>= 1) j ^= k;
j ^= k;
if (i < j) swap(a[i], a[j]);
}
for (int x = 2; x <= n; x <<= 1) {
unsigned int w = pwr(G, (M - 1) / x);
if (b) w = inv(w);
for (int i = 0; i < n; i += x) {
unsigned int z = 1;
for (int j = 0; j < x / 2; j++) {
unsigned int u = a[i + j];
unsigned int y = 1ULL * a[i + j + x / 2] * z % M;
a[i + j] = (u + y >= M ? u + y - M : u + y);
a[i + j + x / 2] = (u < y ? u - y + M : u - y);
z = 1ULL * z * w % M;
}
}
}
if (b) {
unsigned int r = inv(n);
for (unsigned int &x : a) x = 1ULL * x * r % M;
}
}
vector<unsigned int> mul(vector<unsigned int> const& a, vector<unsigned int> const& b) {
if (a.empty() || b.empty()) return {};
vector<unsigned int> x(a.begin(), a.end()), y(b.begin(), b.end());
int n = 1;
while (n < a.size() + b.size()) n <<= 1;
x.resize(n); y.resize(n);
Ntt(x, false); Ntt(y, false);
for (int i = 0; i < n; i++) x[i] = 1ULL * x[i] * y[i] % M;
Ntt(x, true);
vector<unsigned int> r(a.size() + b.size() - 1);
for (int i = 0; i < r.size(); i++) r[i] = x[i];
return r;
}
signed main(){
fast
if (fopen("mint.inp", "r")){
freopen("mint.inp", "r", stdin);
freopen("mint.out", "w", stdout);
}
pre();
int n, q; cin >> n >> q;
int d = n;
for (int i = 0; i <= n; i++) cin >> p[i];
unsigned int c = 0;
unsigned int l = 0;
for (int i = 0; i < q; i++) {
char o; cin >> o;
if (o == 'D') {
if (d >= 0) {
if (c == 0) {
for (int j = 0; j < d; j++) p[j] = p[j + 1];
p[d] = 0;
d--;
}
else {
unsigned int x = p[d];
p[d] = 0;
for (int j = d - 1; j >= 0; j--) {
unsigned int y = p[j];
p[j] = x;
x = (y + 1ULL * c * x) % M;
}
d--;
}
}
}
else if (o == 'S') {
unsigned int x;
cin >> x;
x ^= l;
c = (c + x) % M;
}
else if (o == 'M') {
int m; cin >> m;
vector<unsigned int> b(m);
for (int j = 0; j < m; j++) cin >> b[j];
if (c != 0) {
vector<unsigned int> x(m);
for (int j = 0; j < m; j++) x[j] = 1ULL * b[j] * f[j] % M;
vector<unsigned int> y(m);
for (int j = 0; j < m; j++) y[j] = x[m - 1 - j];
vector<unsigned int> z(m);
unsigned int u = (M - c) % M;
unsigned int w = 1;
for (int j = 0; j < m; j++) {
z[j] = 1ULL * w * v[j] % M;
w = 1ULL * w * u % M;
}
vector<unsigned int> k = mul(y, z);
vector<unsigned int> r(m);
for (int j = 0; j < m; j++) r[j] = 1ULL * k[m - 1 - j] * v[j] % M;
b = r;
}
if (d >= 0) {
vector<unsigned int> x(p, p + d + 1);
vector<unsigned int> y = mul(x, b);
d = y.size() - 1;
for (int j = 0; j <= d; j++) p[j] = y[j];
}
}
else if (o == 'Q') {
int t; cin >> t;
t ^= l;
unsigned int a = 0;
if (t > d) a = 0;
else {
if (c == 0) a = 1ULL * p[t] * f[t] % M;
else {
unsigned int x = 0;
for (int j = d; j >= t; j--) {
unsigned int y = 1ULL * p[j] * f[j] % M * v[j - t] % M;
x = (1ULL * x * c + y) % M;
}
a = x;
}
}
cout << a << "\n";
l = a;
}
}
return 0;
}