#include <bits/stdc++.h>

#define int long long

using namespace std;

const int N = 1e5 + 10, mod = 998244353;

int pd(int x, int t) {
    if (t == 0) return 1ll;
    int k = pd(x, t / 2) % mod;
    if (t % 2 == 1) {
        return ((x * k) % mod * k) % mod;
    }
    return (k * k) % mod;
}

void solve() {
    int n, q;
    cin >> n >> q;
    vector<int> a(n);
    bool f = true;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
        if (a[i] != i + 1) {
            f = false;
        }
    }
    int ans[2][2];
    for (int i = 0; i < 2; ++i) {
        for (int j = 0; j < 2; ++j) {
            vector<int> b = a;
            if (i == 1) {
                for (int k = 0; k < n; ++k) {
                    b[k] = a[n - k - 1];
                }
            }
            if (j == 1) {
                for (int k = 0; k < n; ++k) {
                    b[k] = n - b[k] + 1;
                }
            }
            int sum = 0;
            for (int k = 0; k < n; ++k) {
                sum += pd(b[k], k + 1);
                sum %= mod;
            }
            ans[i][j] = sum;
        }
    }
    int th = 0;
    vector<int> b(n);
    for (int i = 0; i < n; ++i) {
        b[a[i] - 1] = i + 1;
    }
    for (int i = 0; i < n; ++i) {
        th += pd(b[i], i + 1);
        th %= mod;
    }
    int x = 0, y = 0, z = 0;
    for (int e = 0; e < q; ++e) {
        int t;
        cin >> t;
        if (t == 1) {
            x = (x + 1) % 2;
        } else if (t == 2) {
            y = (y + 1) % 2;
        } else {
            z = (z + 1) % 2;
        }
        if (f || z == 0) {
            cout << ans[x][y] << ' ';
        } else {
            cout << th << ' ';
        }
    }
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int dota = 1;
    //cin >> dota;
    while (dota--) {
        solve();
        cout << '\n';
    }
    return 0;
}
