#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define F first
#define S second
#define pb push_back
#define all(x) x.begin(), x.end()
// #define int long long
const int MOD = 998244353;

int mult(const int a, const int b) {
    return ((ll) a * (ll) b) % MOD;
}

int add(int a, int b) {
    if (a + b < MOD) {
        return a + b;
    }
    return a + b - MOD;
}

int binpow(int a, int b) {
    if (b == 0) {
        return 1;
    } else if (b == 1) {
        return a;
    } else if (b % 2 == 1) {
        return mult(a, binpow(a, b - 1));
    } else {
        int x = binpow(a, b / 2);
        return mult(x, x);
    }
}


const int N = 1e5 + 100;
int a[N];
pair<int, int> v[N];

int n, q;

int getans() {
    int ans = 0;
    for (int i = 1; i <= n; ++i) {
        ans = add(ans, binpow(v[i].S, v[i].F));
    }
    return ans;
}

int ans[2][2][2];

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    cin >> n >> q;
    for (int i = 1; i <= n; ++i) {
        cin >> a[i];
    }
    for (int x = 0; x < 2; ++x) {
        for (int y = 0; y < 2; ++y) {
            for (int z = 0; z < 2; ++z) {
                for (int i = 1; i <= n; ++i) {
                    v[i] = {
                        (x == 0 ? i : n - i + 1),
                        (y == 0 ? a[i] : n - a[i] + 1)
                    };
                    if (z == 1) {
                        swap(v[i].F, v[i].S);
                    }
                }
                ans[x][y][z] = getans();
            }
        }
    }
    int x = 0, y = 0, z = 0;
    while (q--) {
        int type;
        cin >> type;
        if (type == 1) {
            if (z == 0) {
                x = 1 - x;
            } else {
                y = 1 - y;
            }
        } else if (type == 2) {
            if (z == 0) {
                y = 1 - y;
            } else {
                x = 1 - x;
            }
        } else {
            z = 1 - z;
        }
        cout << ans[x][y][z] << ' ';
    }
    return 0;
}
