#include <bits/stdc++.h>

using namespace std;

#define int long long
#define double long double

int inf = (int)1000 * 1000 * 1000 * 1000 * 1000 * 1000 + 100;
// int inf = (int)1000 * 1000 * 1000 + 100;

/*
#pragma optimize("O3")
#pragma optimize("avx,avx2,bmi,bmi2")
*/

mt19937_64 rnd(228);

int mod = 998244353;

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

int umn(int a, int b, int c) {
    return umn(a, umn(b, c));
}

int umn(int a, int b, int c, int d) {
    return umn(a, umn(b, c, d));
}

int umn(int a, int b, int c, int d, int e) {
    return umn(a, umn(b, c, d, e));
}

int bin_pow(int a, int x) {
    if (x == 0) {
        return 1;
    }
    if (x % 2 == 0) {
        return bin_pow(umn(a, a), x / 2);
    }
    return umn(a, bin_pow(a, x - 1));
}

vector <int> rev(vector <int> p) {
    vector <int> q(p.size());
    for (int i = 0; i < q.size(); i ++) {
        q[i] = p[p.size() - i - 1];
    }
    return q;
}

vector <int> rev2(vector <int> p) {
    vector <int> q(p.size());
    for (int i = 0; i < p.size(); i ++) {
        q[i] = p.size() - p[i] + 1;
    }
    return q;
}

vector <int> obr(vector <int> p) {
    vector <int> q(p.size());
    for (int i = 0; i < p.size(); i ++) {
        q[p[i] - 1] = i + 1;
    }
    return q;
}

int count(vector <int> a) {
    int cnt = 0;
    for (int i = 0; i < a.size(); i ++) {
        cnt += bin_pow(a[i], i + 1);
        cnt %= mod;
    }
    return cnt;
}

void print(vector <int> a) {
    for (int i = 0; i < a.size(); i ++) {
        cout << a[i] << " ";
    }
    cout << '\n';
}

void solve() {
    int n, q;
    cin >> n >> q;
    vector <int> a(n);
    for (int i = 0; i < n; i ++) {
        cin >> a[i];
    }

    vector <vector <int>> t1(2, vector <int> (2, 0));
    for (int i = 0; i < 2; i ++) {
        for (int j = 0; j < 2; j ++) {
            auto p = a;
            if (i) {
                p = rev(p);
            }
            if (j) {
                p = rev2(p);
            }
            t1[i][j] = count(p);
        }
    }
    vector <vector <vector <vector <int>>>> t2(2, vector <vector <vector <int>>> (2, vector <vector <int>> (2, vector <int> (2, 0))));
    for (int i = 0; i < 2; i ++) {
        for (int j = 0; j < 2; j ++) {
            for (int k = 0; k < 2; k ++) {
                for (int l = 0; l < 2; l ++) {
                    auto p = a;
                    if (i) {
                        p = rev(p);
                    }
                    if (j) {
                        p = rev2(p);
                    }

                    p = obr(p);

                    if (k) {
                        p = rev(p);
                    }
                    if (l) {
                        p = rev2(p);
                    }

                    t2[i][j][k][l] = count(p);
                }
            }
        }
    }

    int i = 0;
    int j = 0;
    int k = 0;
    int g = 0;
    int h = 0;

    while (q --) {
        int f;
        cin >> f;

        if (k == 0) {
            if (f == 1) {
                i = 1 - i;
            }
            else if (f == 2) {
                j = 1 - j;
            }
            else {
                k = 1;
            }
        }
        else {
            if (f == 1) {
                g = 1 - g;
            }
            else if (f == 2) {
                h = 1 - h;
            }
            else {
                k = 0;
                if (g == 0 && h == 0) {

                }
                else if (g == 1 && h == 1) {
                    i = 1 - i;
                    j = 1 - j;
                }
                else if (g == 1) {
                    j = 1 - j;
                }
                else if (h == 1) {
                    i = 1 - i;
                }

                g = 0;
                h = 0;
            }
        }

        if (k == 0) {
            cout << t1[i][j] << " ";
        }
        else {
            cout << t2[i][j][g][h] << " ";
        }

        // cout << t[i][j][k] << " ";

        // if (f == 1) {
        //     a = rev(a);
        // }
        // else if (f == 2) {
        //     a = rev2(a);
        // }
        // else {
        //     a = obr(a);
        // }

        // cout << count(a) << " ";
        // for (int ii = 0; ii < a.size(); ii ++) {
        //     cout << a[ii] << " ";
        // }
        // cout << '\n';
    }
    // cout << '\n';

    /*
    // print(rev(obr(rev(obr(a)))));
    // print(obr(obr(a)));
    print(rev(obr(rev2(obr(a)))));
    // print(rev(rev2(a)));
    // print(rev(rev2(rev(rev2(a)))));
    print(rev2(obr(rev(obr(a)))));
    cout << '\n';

    // print(rev(rev2(a)));
    // print(obr(a));
    print(obr(rev(obr(a))));
    print(rev2(a));
    cout << '\n';

    print(obr(rev2(obr(a))));
    print(rev(a));
    cout << '\n';

    print(obr(rev2(rev(obr(a)))));
    print(rev2(rev(a)));
    // print(rev(a));
    */
}

signed main() {
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#else
    ios_base::sync_with_stdio(0);
    cin.tie(0);
#endif

    int _ = 1;
    // cin >> _;
    while (_ --) {
        solve();
    }
}