#include <bits/stdc++.h>

using namespace std;

const long long MOD = 998224353;

long long bin(long long a, int k) {
    if (k == 0) {
        return 1;
    }
    long long b = bin(a, k / 2);
    b *= b;
    b %= MOD;
    if (k % 2 == 1) {
        b *= a;
        b %= MOD;
    }
    return b;
}

int main()
{
    int n, q;
    cin >> n >> q;
    vector <long long> v(n);
    for (int i = 0; i < n; ++i) {
        cin >> v[i];
    }
    vector <long long> ans(8, 0);
    for (int i = 0; i < 8; ++i) {
        int j = i;
        int a = j % 2;
        j /= 2;
        int b = j % 2;
        j /= 2;
        int c = j % 2;
        vector <long long> p(n);
        for (int t = 0; t < n; ++t) {
            p[t] = v[t];
        }
        if (a) {
            vector <long long> q(n);
            for (int i = 0; i < n; ++i) {
                q[i] = p[n - i - 1];
            }
            for (int i = 0; i < n; ++i) {
                p[i] = q[i];
            }
        }
        if (b) {
            vector <long long> q(n);
            for (int i = 0; i < n; ++i) {
                q[i] = n - p[i] + 1;
            }
            for (int i = 0; i < n; ++i) {
                p[i] = q[i];
            }
        }
        if (c) {
            vector <long long> q(n);
            for (int i = 0; i < n; ++i) {
                q[p[i] - 1] = i + 1;
            }
            for (int i = 0; i < n; ++i) {
                p[i] = q[i];
            }
        }
        int k = 4 * c + 2 * b + a;
        for (int i = 0; i < n; ++i) {
            ans[k] += bin(p[i], (i + 1));
            ans[k] %= MOD;
        }
    }
    int a = 0;
    int b = 0;
    int c = 0;
    while (q--) {
        int t;
        cin >> t;
        if (t == 1) {
            a++;
            a %= 2;
        } else if (t == 2) {
            b++;
            b %= 2;
        } else {
            c++;
            c %= 2;
        }
        cout << ans[4 * c + 2 * b + a] << endl;
    }
    return 0;
}
