#include <bits/stdc++.h>
#define print(a) for (auto i : a) cout << i << " "; cout << "\n";
using namespace std;
using ll = long long;
using pi = pair<int, int>;
using pl = pair<ll, ll>;

const int mod = 998244353;

ll binpow(ll a, int n) {
    if (n == 1) return a;
    ll res = 1;
    while (n > 1) {
        if (n&1) res = res*a % mod;
        res = res*a*a % mod;
        n >>= 1;
    }
    return res % mod;
}

ll cnt(const vector<int> &a) {
    ll res = 0;
    for (int i = 0; i < a.size(); i++) {
        res += binpow(a[i], i+1) % mod;
        res %= mod;
    }
    return res;
}

void solve(const vector<int> &b, vector<int> &p, int n, int q) {
    for (int k = 0; k < q; k++) {
        int t = b[k];
        if (t == 1) {
            reverse(p.begin(), p.end());
            cout << cnt(p) << " ";
        } else if (t == 2) {
            for (int i = 0; i < n; i++) {
                p[i] = n - p[i] + 1;
            }
            cout << cnt(p) << " ";
        } else {
            vector<int> nw(n);
            for (int i = 0; i < n; i++) {
                nw[p[i]-1] = i+1;
            }
            p = nw;
            cout << cnt(p) << " ";
        }
    }
}

int main() {
    // freopen("C:/work/untitled/input.txt", "r", stdin);
    // ios::sync_with_stdio(false);
    // cin.tie(nullptr);
    int n, q;
    cin >> n >> q;
    vector<int> p(n);
    for (int i = 0; i < n; i++) {
        cin>>p[i];
    }
    ll ab = 0, a = 0 , b = 0, s = 0;
    vector<int> p2(n, 0);
    for (int i = 0; i < n; i++) {
        p2[i] = n - p[i] + 1;
    }
    for (int i = 0; i < n; i++) {
        ab += binpow(p2[i], n-i);
        ab %= mod;
        a += binpow(p[i], n-i);
        a %= mod;
        b += binpow(p2[i], i+1);
        b %= mod;
        s += binpow(p[i], i+1);
        s %= mod;
    }
    int c1 = 0, c2 = 0;
    vector<int> qr(q);
    for (int i = 0; i < q; i++) cin >> qr[i];
    for (int i = 0; i < q; i++) {
        int t = qr[i];
        if (t == 1) c1++;
        else c2++;

        if (c1&1 && c2&1) cout << ab;
        else if (c1&1) cout << a;
        else if (c2&1) cout << b;
        else cout << s;
        cout << " ";
    }
    cout << "\n";
    // solve(qr, p, n, q);
}
