#include <bits/stdc++.h>
using namespace std;
using ll = long long;

const ll mod = 998'244'353;

ll mpow(ll a, ll b) {
    if (b == 0) return 1LL;
    if (b % 2) {
        return (a * mpow(a, b - 1)) % mod;
    } else {
        ll x = mpow(a, b / 2);
        return (x * x) % mod;
    }
}


ll calc(vector<int> a) {
    ll val = 0;
    int n = (int)a.size();
    for (int i = 0; i < n; ++i) {
        val += mpow((ll)a[i], (ll)(i + 1));
        val %= mod;
    }
    return val; 
}

void transform(vector<int>& a, int t) {
    int n = (int)a.size();
    if (t == 1) {
        reverse(a.begin(), a.end());
    } else if (t == 2) {
        for (int i = 0; i < n; ++i) {
            a[i] = n - a[i] + 1;
        }
    } else {
        vector<int> b(n, -1);
        for (int i = 0; i < n; ++i) {
            b[a[i] - 1] = i + 1;
        }
        a = b;
    }
}

int main() {
    int n, q;
    cin >> n >> q;
    vector<int> a(n);
    for (int& x : a) cin >> x;
    vector<int> Q(q);
    for (int i = 0; i < q; ++i) {
        cin >> Q[i];
    }
    bool flg = true;
    for (int i = 0; i < n; ++i) {
        if (a[i] != i + 1) {
            flg = false;
        }
    }
    if (flg) {
        bool rev = false;
        ll v = calc(a);
        reverse(a.begin(), a.end());
        ll rv = calc(a);
        for (auto t : Q) {
            if (!rev) {
                if (t <= 2) {
                    cout << rv << ' ';
                    rev = true;
                } else {
                    cout << v << ' ';
                }
            } else {
                if (t <= 2) {
                    rev = false;
                    cout << v << ' ';
                } else {
                    cout << rv << ' ';
                }
            }
        }
        return 0;
    }
    flg = true;
    for (int i = 1; i < q; ++i) {
        if (Q[i] != Q[0]) flg = false;
    }
    if (flg) {
        int t = Q[0];
        ll v = calc(a);
        transform(a, t);
        ll rv = calc(a);
        for (int i = 0; i < q; ++i) {
            if (i % 2) {
                cout << v << ' ';
            } else {
                cout << rv << ' ';
            }
        }
        return 0;
    }
    for (int t : Q) {
        transform(a, t);
        cout << calc(a) << ' ';
    }
    return 0;
}