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

const ll mod = 998244353;

ll binpow(ll x, ll st) {
    if (st == 0) return 1;
    if (st == 1) return x % mod;
    ll bp = binpow(x, st / 2) % mod;
    if (st % 2 == 0) return bp % mod * bp % mod;
    return bp % mod * bp % mod * x % mod;
}

ll n, q;

void com1(vector<ll>& arr) {
    vector<ll> p = arr;
    for (ll i = 1; i <= n; ++i) {
        arr[i] = p[n - i + 1];
    }
}

void com2(vector<ll>& arr) {
    vector<ll> p = arr;
    for (ll i = 1; i <= n; ++i) {
        arr[i] = n - p[i] + 1;
    }
}

void com3(vector<ll>& arr) {
    vector<ll> p = arr;
    for (ll i = 1; i <= n; ++i) {
        arr[i] = p[n - i + 1];
    }
}

ll calc(vector<ll>& arr) {
    ll ans = 0;
    for (ll i = 1; i <= n; ++i) {
        ans += binpow(arr[i], i);
    }
    return ans;
}

void solve() {
    cin >> n >> q;
    vector<ll> arr(n + 1);
    for (ll i = 1; i <= n; ++i) {
        cin >> arr[i];
    }
    com1(arr);
    ll ans = 0;
    for (ll i = 1; i <= n; ++i) {
        ans += binpow(arr[i], i);
    }
    vector<vector<ll>> answer(2, vector<ll>(2));
    for (ll i = 0; i < 2; ++i) {
        for (ll j = 0; j < 2; ++j) {
            if (i == 0 && j == 0) {
                ll ans = calc(arr);
                answer[i][j] = ans;
            }
            if (i == 0 && j == 1) {
                com2(arr);
                ll ans = calc(arr);
                answer[i][j] = ans;
                com2(arr);
            }
            if (i == 1 && j == 0) {
                com1(arr);
                ll ans = calc(arr);
                answer[i][j] = ans;
                com1(arr);
            }
            if (i == 1 && j == 1) {
                com1(arr);
                com2(arr);
                ll ans = calc(arr);
                answer[i][j] = ans;
                com2(arr);
                com1(arr);
            }
        }
    }
    ll a = 0, b = 0;
    for (ll i = 0; i < q; ++i) {
        ll com;
        cin >> com;
        if (com == 1) {
            a = !a;
        } else {
            b = !b;
        }
        cout << answer[a][b] << ' ';
    }
}

signed main() {
    ll t = 1;
    while (t--) {
        solve();
    }
}