#include <bits/stdc++.h>

using namespace std;

#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("avx2")

#define int long long
#define pb push_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define ff first
#define ss second
#define itn int
#define Auto auto

const int maxn = 2e5 + 10;
const int logn = 20;
const int B = 300;
const int inf = 4e18;
const int mod = 1e9 + 7;
const int mod1 = 998244353;


#ifdef LOCAL
#define debug(x) cerr << (#x) << ": " << x << endl;
#define debugv(x) cerr << (#x) << ": " << "[ "; for(auto t : x){cerr << t << ' ';} cerr << "]" << endl;
#endif


int binpow(int x, itn y) {
    if (y == 0) {
        return 1ll;
    }
    if (y % 2 == 0) {
        int bas = binpow(x, y / 2) % mod1;
        return bas * bas % mod1;
    } else {
        return (x * binpow(x, y - 1) % mod1) % mod1;
    }
}

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

void opos(vector<int> &b) {
    for (auto &t: b) {
        t = (int) (b.size()) + 1 - t;
    }
}

void perev(vector<int> &b) {
    reverse(all(b));
}

void solve() {
    int n, q;
    cin >> n >> q;
    vector<int> per(n);
    for (auto &t: per) {
        cin >> t;
    }
    vector<int> cur = per;
    int ans = get(cur);
    perev(cur);
    int ans1 = get(cur);
    int sost = 0;
    while (q--) {
        int t;
        cin >> t;
        if (t == 3) {
            if (sost % 2 == 0) {
                cout << ans << ' ';
            } else {
                cout << ans1 << ' ';
            }
        } else if (t == 2) {
            if (sost % 2 == 0) {
                cout << ans1 << ' ';
            }else {
                cout << ans << ' ';
            }
            sost = (sost + 1) % 2;
        }else {
            if (sost % 2 == 0) {
                cout << ans1 << ' ';
            }else {
                cout << ans << ' ';
            }
            sost = (sost + 1) % 2;
        }

    }
}


signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    int t = 1;
    //cin >> t;
    while (t--) {
        solve();
        cout << '\n';
    }
    return 0ll;
}
