#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 solve() {
    int n, q;
    cin >> n >> q;
    vector <int> a(n);
    for (int i = 0; i < n; i ++) {
        cin >> a[i];
    }

    vector <vector <vector <int>>> t(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 ++) {
                vector <int> p = a;
                if (i) {
                    p = rev(p);
                }
                if (j) {
                    p = rev2(p);
                }
                if (k) {
                    p = obr(p);
                }

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

    int i = 0;
    int j = 0;
    int k = 0;
    while (q --) {
        int f;
        cin >> f;
        if (f == 1) {
            i = 1 - i;
        }
        else if (f == 2) {
            j = 1 - j;
        }
        else if (f == 3) {
            k = 1 - k;
        }
        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) << " ";
    }
    cout << '\n';
}

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();
    }
}