#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <map>
#include <set>
#include <queue>

using namespace std;

const long long MOD = 998244353;

long long binpow(long long a, long long b) {
    long long x = 1, c = a;
    vector<pair<long long, long long>> v = {{a, 1}};
    while (x * 2 <= b) {
        c *= c;
        c %= MOD;
        x *= 2;
        v.push_back({c, x});
    }
    long long x1 = x, k = 0;
    while (x1 > 0) {
        x1 /= 2;
        k++;
    }
    for (int j = k - 2; j >= 0; j--) {
        if (x + v[j].second <= b) {
            c *= v[j].first;
            c %= MOD;
            x += v[j].second;
        }
    }
    return c;
}

int main() {
    int n, q;
    cin >> n >> q;
    vector<long long> v(n), b(q);
    for (int i = 0; i < n; i++) {
        cin >> v[i];
    }
    long long ans1 = 0, ans2 = 0;
    for (int i = 0; i < n; i++) {
        long long c = binpow(v[i], i + 1);
        ans1 += c;
        ans1 %= MOD;
    }
    reverse(v.begin(), v.end());
    for (int i = 0; i < n; i++) {
        long long c = binpow(v[i], i + 1);
        ans2 += c;
        ans2 %= MOD;
    }
    int ok = 0;
    for (int i = 0; i < q; i++) {
        int t; cin >> t;
        if (t == 1 || t == 2) {
            ok++;
            if (ok % 2 == 0) {
                cout << ans1 << ' ';
            } else {
                cout << ans2 << ' ';
            }
        } else {
            if (ok % 2 == 0) {
                cout << ans1 << ' ';
            } else {
                cout << ans2 << ' ';
            }
        }
    }
}
