#include <bits/stdc++.h>

using namespace std;
using ll = long long;
#define all(x) x.begin(), x.end()

const ll MOD = 998244353;


struct mint {
    ll x;

    mint(ll s = 0) {
        x = s;
    }

    mint operator+(mint other) {
        mint res;
        res.x = x + other.x;
        if (res.x > MOD) {
            res.x -= MOD;
        }
        return res;
    }

    mint operator-(mint other) {
        mint res;
        res.x = x - other.x;
        if (res.x < 0) {
            res.x += MOD;
        }
        return res;
    }

    mint operator*(mint other) {
        mint res;
        res.x = x * other.x;
        res.x %= MOD;
        return res;
    }

    mint binpow(ll n) {
        if (n == 0) return 1;
        if (n == 1) {
            return (*this);
        }
        if (n % 2 == 0) {
            mint lr = binpow(n / 2);
            return lr * lr;
        }
        return (*this) * binpow(n - 1);
    }
};


ll comply(vector<ll> & p) {
    mint ans = 0;
    for (int i = 1; i < p.size(); ++i) {
        ans = ans + mint(p[i]).binpow(i);
    }
    return ans.x;
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    ll n, q;
    cin >> n >> q;
    vector<ll> p(n + 1);
    for (int i = 1; i <= n; ++i) {
        cin >> p[i];
    }

    vector<vector<ll>> cur(2, vector<ll> (2));
    cur[0][0] = comply(p);
    vector<ll> nq(n + 1);
    for (int i = 1; i <= n; ++i) {
        nq[i] = p[n - i + 1];
    }
    cur[1][0] = comply(nq);
    for (int i = 1; i <= n; ++i) {
        nq[i] = n - nq[i] + 1;
    }
    cur[1][1] = comply(nq);
    for (int i = 1; i <= n; ++i) {
        nq[i] = nq[n - i + 1];
    }
    cur[0][1] = comply(nq);

    ll t1 = 0;
    ll t2 = 0;
    for (int i = 0; i < q; ++i) {
        ll b;
        cin >> b;
        if (b == 1) {
            t1 = 1 - t1;
        }
        if (b == 2) {
            t2 = 1 - t2;
        }
        cout << cur[t1][t2] << ' ';
    }
}