#include <bits/stdc++.h>

using namespace std;
using ll = long long;
const int inf = 1e9;
// const ll inf = 1e18;

const ll mod = 998244353;
struct mll {
    ll v;

    mll(ll v_) {
        v = v_;
    }

    mll() {}

    mll operator*(mll b) const {
        return mll(v * b.v % mod);
    }

    mll operator+(mll b) const {
        if (v + b.v < mod) {
            return mll(v + b.v);
        }
        return mll(v + b.v - mod);
    }
};

mll binPow(mll b, int p) {
    if (p == 0) {
        return mll(1);
    }
    if (p % 2 == 0) {
        mll res = binPow(b, p / 2);
        return res * res;
    }
    return binPow(b, p - 1) *b;
}

mll calc(vector<mll> &v) {
    mll res = 0;
    for (int i = 0; i < (int) v.size(); ++i) {
        res = res + binPow(v[i], i + 1);
    }

    return res;
}

vector<mll> inv(vector<mll> &v) {
    int n = v.size();
    vector<mll> res = v;
    for (int i = 0; i < n; ++i) {
        res[i] = n - res[i].v + 1;
    }
    return res;
}

vector<mll> ord(vector<mll> &v) {
    int n = v.size();
    vector<mll> res(n);
    for (int i = 0; i < n; ++i) {
        res[v[i].v - 1] = i + 1;
    }
    return res;
}

void solve() {
    int n, q;
    cin >> n >> q;

    vector<mll> p(n);
    for (int i = 0; i < n; ++i) {
        cin >> p[i].v;
    }

    while (q--) {
        int b;
        cin >> b;

        if (b == 1) {
            reverse(p.begin(), p.end());
            cout << calc(p).v << " ";
        } else if (b == 2) {
            p = inv(p);
            cout << calc(p).v << " ";
        } else {
            p = ord(p);
            cout << calc(p).v << " ";
        }
    }
}

int main() {
    cin.tie(0);
    cout.tie(0);
    cin.sync_with_stdio(0);
    cout.sync_with_stdio(0);

    int d = 1;
    // cin >> d;

    while(d--) {
        solve();
        cout << "\n";
    }
}
