#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
using oset = tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>;
#define int long long
const int mod = 998244353;

int add(int a, int b) {
    if (a + b >= mod) return a + b - mod;
    return a + b;
}

int sub(int a, int b) {
    if (a - b < 0) return a - b + mod;
    return a - b;
}

int mul(int a, int b) {
    return (a * b) % mod;
}

int bpow(int x, int st) {
    if (st == 0) return 1;
    if (st == 1) return x;
    int xx = bpow(x, st / 2);
    xx = mul(xx, xx);
    if (st % 2 == 1) {
        xx = mul(xx, x);
    }
    return xx;
}

void solve() {
    int n, q;
    cin >> n >> q;
    vector<int> a(n + 1);
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
    }
    int ans0 = 0, ans1 = 0, ans2 = 0, ans3 = 0;
    for (int i = 1; i <= n; i++) {
        ans0 = add(ans0, bpow(a[i], i));
    }
    vector<int> a1 = a;
    vector<int> a2 = a;
    vector<int> a3 = a;
    for (int i = 1; i <= n; i++) {
        a1[i] = a[n - i + 1];
    }
    for (int i = 1; i <= n; i++) {
        a2[i] = n - a[i] + 1;
    }
    for (int i = 1; i <= n; i++) {
        a3[i] = n - a1[i] + 1;
    }
    for (int i = 1; i <= n; i++) {
        ans1 = add(ans1, bpow(a1[i], i));
    }
    for (int i = 1; i <= n; i++) {
        ans2 = add(ans2, bpow(a2[i], i));
    }
    for (int i = 1; i <= n; i++) {
        ans3 = add(ans3, bpow(a3[i], i));
    }
    vector<int> op;
    for (int _ = 0; _ < q; _++) {
        int tp;
        cin >> tp;
        assert((int) op.size() <= 2);
        if (op.empty()) {
            if (tp == 1) {
                cout << ans1 << ' ';
            }
            else {
                cout << ans2 << ' ';
            }
            op.push_back(tp);
        }
        else if ((int) op.size() == 1) {
            if (tp == op[0]) {
                cout << ans0 << ' ';
                op.pop_back();
            }
            else {
                cout << ans3 << ' ';
                op.push_back(tp);
            }
        }
        else if ((int) op.size() == 2) {
            if (tp == op.back()) {
                op.pop_back();
                if (op[0] == 1) {
                    cout << ans1 << ' ';
                }
                else {
                    cout << ans2 << ' ';
                }
            }
            else {
                if (op[0] == 1) {
                    assert(tp == 1);
                    op.pop_back();
                    op.pop_back();
                    op.push_back(2);
                    cout << ans2 << ' ';
                }
                else {
                    assert(tp == 2);
                    op.pop_back();
                    op.pop_back();
                    op.push_back(1);
                    cout << ans1 << ' ';
                }
            }
        }
    }
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int tt = 1;
    //cin >> tt;
    while (tt--) {
        solve();
    }
    return 0;
}