#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

typedef long long ll;
typedef long double ld;
#define int long long
#define pii pair<int, int>
#define F first
#define S second

const int mod = 998244353;

vector<int> a;

int pow(int b, int c) {
    if (c == 0) {
        return 1;
    }
    if (c % 2 == 0) {
        int x = pow(b, c / 2);
        return x * x % mod;
    }
    return pow(b, c - 1) * b % mod;
}

int give() {
    int ans = 0;
    for (int i = 0; i < a.size(); i++) {
        ans = (ans + pow(a[i], i + 1)) % mod;
    }
    return ans;
}

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n, q;
    cin >> n >> q;
    a.resize(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    int ans1 = give(), ans2 = -1, ty = 0;
    for (int i = 0; i < n / 2; i++) {
        swap(a[i], a[n - 1 - i]);
    }
    ans2 = give();
    for (int i = 0; i < q; i++) {
        int t;
        cin >> t;
        if (t == 1) {
            ty = 1 - ty;
        } else if (t == 2) {
            ty = 1 - ty;
        } else {
            ty = 0;
        }
        if (ty == 0) {
            cout << ans1 << " ";
        } else {
            cout << ans2 << " ";
        }
        //cout << give() << " ";
    }
    return 0;
} 