#include <iostream>
#include <cmath>
#include <algorithm>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <numeric>
#include <iomanip>
#include <random>
#include <ranges>
#include <chrono>
#define eb emplace_back

using namespace std;

using ll = long long;
using lll = __int128;
using db = double;
using ld = long double;

const int INF = 1'000'000'000;
const ll LINF = 1'000'000'000'000'000'000;
const ll MOD = 998'244'353;

int rnd() {
    return (rand() / RAND_MAX);
}

ll modSum(ll a, ll b) {
    ll ans = a + b;
    if (ans >= MOD) {
        ans -= MOD;
    }
    return ans;
}

ll modMinus(ll a, ll b) {
    ll ans = a - b;
    if (ans < 0) {
        ans += MOD;
    }
    return ans;
}

ll modMul(ll a, ll b) {
    ll ans = (a * b) % MOD;
    return ans;
}

ll modPow(ll a, ll pw) {
    if (pw == 0) {
        return 1;
    }
    ll ans = modPow(a, pw / 2);
    ans = modMul(ans, ans);
    if (pw % 2 == 1) {
        ans = modMul(ans, a);
    }
    return ans;
}

vector <ll> p;
int n;

ll getScore() {
    ll ans = 0;
    for (int i = 0; i < n; ++i) {
        ans = modSum(ans, modPow(p[i], i + 1));
    }
    return ans;
}

int main() {
    ios_base::sync_with_stdio();
    cin.tie(nullptr);
    int Q;
    cin >> n >> Q;
    p.resize(n);
    for (int i = 0; i < n; ++i) {
        cin >> p[i];
    }
    while (Q--) {
        int b;
        cin >> b;
        if (b == 1) {
            reverse(p.begin(), p.end());
            cout << getScore() << ' ';
        } else if (b == 2) {
            for (int i = 0; i < n; ++i) {
                p[i] = n - p[i] + 1;
            }
            cout << getScore() << ' ';
        } else {
            vector <ll> q(n);
            for (int i = 0; i < n; ++i) {
                q[p[i] - 1] = i + 1;
            }
            p.swap(q);
            cout << getScore() << ' ';
        }
    }
}