#include <bits/stdc++.h>

// #pragma GCC optimize("Ofast")

using namespace std;

using ll = long long;
using ld = long double;

constexpr long long INF = 1e18, MOD = 998244353;


ll binpow(ll x, ll st) {
    if (st == 1) {
        return x % MOD;
    }
    if (st == 0) {
        return 1;
    }
    ll z = binpow(x, st / 2);
    z *= z;
    z %= MOD;
    if (st % 2 == 0) {
        return z;
    }
    else {
        return (x * z) % MOD;
    }
}

ll cost(vector<ll> &a) {
    ll n = (ll)a.size();
    ll ans= 0;
    for (ll i = 0; i < n; ++i) {
        ans += binpow(a[i], i + 1);
        ans %= MOD;
    }
    return ans;
}

vector<ll> fi(vector<ll> a) {
    reverse(a.begin(), a.end());
    return a;
}
vector<ll> se(vector<ll> a) {
    vector<ll> b((ll) a.size());
    for (ll i = 0; i < (ll) a.size(); ++i) {
        b[i] = (ll)a.size() - a[i] + 1;
    }
    return b;
}

vector<ll> th(vector<ll> a) {
    vector<ll> b((ll) a.size());
    for (ll i = 0; i < (ll) a.size(); ++i) {
        b[a[i] - 1] = i + 1;
    }
    return b;
}

ll ans[2][2][2];
vector<ll> v[2][2][2];

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    ll n, q;
    cin >> n >> q;
    vector<ll> a(n);
    for (auto &v : a) {
        cin >> v;
    }
    for (ll i = 0; i < 2; ++i) {
        for (ll j = 0; j < 2; ++j) {
            for (ll k = 0; k < 2; ++k) {
                vector<ll> b = a;
                if (i == 1) {
                    b = fi(b);
                }
                if (j == 1) {
                    b = se(b);
                }
                if (k == 1) {
                    b = th(b);
                }
                // cout << i << " " << j << " " << k << endl;
                // for (auto u : b) {
                //     cout << u << ' ';
                // }
                // cout << endl;
                ans[i][j][k] = cost(b);
                v[i][j][k] = b;
            }
        }
    }
    if (n <= 1000000000) {
        while (q--) {
            ll c;
            cin >> c;
            if (c == 1) {
                a = fi(a);
            }
            if (c == 2) {
                a = se(a);
            }
            if (c == 3) {
                a = th(a);
            }
            bool f = 0;
            for (ll i = 0; i < 2; ++i) {
                for (ll j = 0; j < 2; ++j) {
                    for (ll k = 0; k < 2; ++k) {
                        if (a == v[i][j][k]) {
                            f = 1;
                        }
                    }
                }
            }
            if (!f) {
                abort();
            }
            cout << cost(a) << '\n';
        }
        return 0;
    }
    vector<ll> now(3);
    while (q--) {
        ll c;
        cin >> c;
        c--;
        // now[c] = (1ll + now[c]) % 2;
        // cout << ans[now[0]][now[1]][now[2]] << " ";
        for (ll i = 0; i < 2; ++i) {
            for (ll j = 0; j < 2; ++j) {
                for (ll k = 0; k < 2; ++k) {
                    ll x = 0;

                }
            }
        }
    }
}