#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> oset;
using ll = long long;
mt19937 rnd(52);
ll mod = 998244353;
vector<int> obr(vector<int> p) {
    vector<int> ans;
    for (int i = 0; i < p.size(); i++) {
        ans[p[i]] = i;
    }
    return ans;
}
vector<int> rev(vector<int> p) {
    vector<int> ans = p;
    reverse(ans.begin(), ans.end());
    return ans;
}
vector<int> inv(vector<int> p) {
    for (int i = 0; i < p.size(); i++) {
        p[i] = p.size() - p[i] + 1;
    }
    return p;
}
ll binpow(ll a, ll p) {
    if (p == 0) {
        return 1;
    }
    if (p%2 == 0) {
        ll t = binpow(a, p/2);
        return t*t%mod;
    } else {
        return binpow(a, p-1)*a%mod;
    }
}
ll answer(vector<int> &p) {
    ll ans = 0;
    for (int i = 0; i < p.size(); i++) {
        ans+=binpow(p[i], i+1);
        ans%=mod;
    }
    return ans;
}
int main() {
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#else
    cin.tie(nullptr);
    ios::sync_with_stdio(0);
#endif
    int n, q;
    cin >> n >> q;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    map<vector<int>, ll> ans;
    vector<int> p = {4, 2, 3, 1};
    ans[a] = answer(a);
    vector<int> pp = inv(a);
    ans[inv(a)] = answer(pp);
    pp = rev(a);
    ans[rev(a)] = answer(pp);
    pp = inv(rev(a));
    ans[inv(rev(a))] = answer(pp);
    for (int i = 0; i < q; i++) {
        int x;
        cin >> x;
        if (x == 1) {
            a = rev(a);
        } else {
            a = inv(a);
        }
        cout << answer(a) << ' ';
    }
    return 0;
}