#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;
using ordered_set = tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>;

#define int long long
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
using pii = pair<int, int>;

const int MOD = 998244353;


int poww(int a, int x) {
    if (x == 0) return 1;
    if (x % 2 == 1) return a * poww(a, x - 1) % MOD;
    int c= poww(a, x / 2);
    return c * c % MOD;
}


int get_ans(vector<int> &a) {
    int ans = 0;
    for (int i = 0; i < a.size(); i++) {
        ans = (ans + poww(a[i], i + 1)) % MOD;;
    }
    return ans;
}

void swapp(vector<int> &a) {
    for (int i = 0; i < a.size(); i++) {
        a[i] = a.size() - a[i] + 1;
    }
}


void solve() {
    int n, q;
    cin >> n >> q;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    vector<int> ans(4);
    ans[0] = get_ans(a);
    reverse(all(a));
    ans[1] = get_ans(a);
    reverse(all(a));
    swapp(a);
    ans[2] = get_ans(a);
    reverse(all(a));
    ans[3] = get_ans(a);

    int curr = 0;
    while (q--) {
        int b;
        cin >> b;
        if (b == 1) {
            curr ^= 1;
        } else if (b == 2){
            curr ^= 2;
        }
        cout << ans[curr] << " ";

    }
    

}


signed main() {
    cin.tie(0);
    cout.tie(0);
    ios_base::sync_with_stdio(false);

    int t = 1;
    // cin >> t;
    while (t--) {
        solve();
    }

}