#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;
    }

    vector<vector<vector<mll>>> res(2, vector<vector<mll>>(2, vector<mll>(2)));
    for (int i = 0; i < 2; ++i) {
        for (int j = 0; j < 2; ++j) {
            for (int k = 0; k < 2; ++k) {
                vector<mll> q = p;
                if (i) {
                    q = inv(q);
                }
                if (j) {
                    reverse(q.begin(), q.end());
                }
                if (k) {
                    q = ord(q);
                }

                res[i][j][k] = calc(q);
            }
        }
    }

    int r = 0, i = 0, o = 0;
    while (q--) {
        int b;
        cin >> b;

        if (b == 1) {
            r = 1 - r;
        } else if (b == 2) {
            i = 1 - i;
        } else if (b == 3) {
            o = 1 - o;
        }

        cout << res[i][r][o].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";
    }
}
