#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cassert>

#define ll long long
#define ld long double
#define ull unsigned long long
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()

using namespace std;

const int MAX = 2e9;
const int MIN = -2e9;
const int mod = 998244353;

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

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

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

int binpow(int a, ll k) {
    int res = 1;
    while (k) {
        if (k % 2) {
            res = mul(res, a);
        }
        a = mul(a, a);
        k /= 2;
    }
    return res;
}

struct segtree {
    struct node {
        int mx;
    };

    const node ZERO = {MIN};
    vector<node> t;
    int size;

    node merge(node a, node b) {
        node res;
        res.mx = max(a.mx, b.mx);
        return res;
    }

    void init(int n) {
        size = 1;
        while (size < n) {
            size *= 2;
        }
        t.assign(size * 2 - 1, ZERO);
    }

    void build(int v, vector<int> &a, int tl, int tr) {
        if (tr - tl == 1) {
            if (tl < a.size()) {
                t[v] = {a[tl]};
            }
            return;
        }
        int mid = (tl + tr) / 2;
        build(v * 2 + 1, a, tl, mid);
        build(v * 2 + 2, a, mid, tr);
        t[v] = merge(t[v * 2 + 1], t[v * 2 + 2]);
    }

    void build(vector<int> &a) {
        init(a.size());
        build(0, a, 0, size);
    }

    node get(int v, int l, int r, int tl, int tr) {
        if (tr <= l or tl >= r) {
            return ZERO;
        }
        if (tl >= l and tr <= r) {
            return t[v];
        }
        int mid = (tl + tr) / 2;
        return merge(get(v * 2 + 1, l, r, tl, mid), get(v * 2 + 2, l, r, mid, tr));
    }

    int get(int l, int r) {
        return get(0, l, r, 0, size).mx;
    }

    void update(int v, int ind, int x, int tl, int tr) {
        if (tr - tl == 1) {
            t[v] = {x};
            return;
        }
        int mid = (tl + tr) / 2;
        if (ind < mid) {
            update(v * 2 + 1, ind, x, tl, mid);
        } else {
            update(v * 2 + 2, ind, x, mid, tr);
        }
        t[v] = merge(t[v * 2 + 1], t[v * 2 + 2]);
    }

    void update(int ind, int x) {
        update(0, ind, x, 0, size);
    }
};

void dany() {
    int n, q;
    cin >> n >> q;
    vector<int> a(n);
    int sum[2][2][2];
    for (int i1 = 0; i1 < 2; i1++) {
        for (int i2 = 0; i2 < 2; i2++) {
            for (int i3 = 0; i3 < 2; i3++) {
                sum[i1][i2][i3] = 0;
            }
        }
    }
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        sum[0][0][0] = add(sum[0][0][0], binpow(a[i], i + 1));
        sum[0][0][1] = add(sum[0][0][1], binpow(n - a[i] + 1, i + 1));
        sum[0][1][0] = add(sum[0][1][0], binpow(a[i], n - i));
        sum[0][1][1] = add(sum[0][1][1], binpow(n - a[i] + 1, n - i));
        sum[1][0][0] = add(sum[1][0][0], binpow(i + 1, a[i]));
        sum[1][0][1] = add(sum[1][0][1], binpow(n - i, a[i]));
        sum[1][1][0] = add(sum[1][1][0], binpow(i + 1, n - a[i] + 1));
        sum[1][1][1] = add(sum[1][1][1], binpow(n - i, n - a[i] + 1));
    }
    int i1 = 0, i2 = 0, i3 = 0;
    while (q--) {
        int b;
        cin >> b;
        if (b == 3) {
            i1 = 1 - i1;
        } else if (b == 2) {
            if (i1) {
                i3=1-i3;
            }
            else {
                i2 = 1 - i2;
            }
        } else {
            if (!i1) {
                i3 = 1 - i3;
            }
            else {
                i2=1-i2;
            }
        }
        cout << sum[i1][i2][i3] << '\n';
    }
}

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    dany();
    return 0;
}
