#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <map>
#include <set>
#include <stack>
#include <queue>

using namespace std;
using T = long long;
using D = long double;
using L = __int128_t;
const int MAXN = 1e5, MOD = 998244353;

T nums[MAXN], tmp[MAXN];

T binPow(T a, T b) {
    T res = 1;
    while (b) {
        if (b % 2) {
            res *= a;
            res %= MOD;
        }

        a *= a;
        a %= MOD;
        b /= 2;
    }

    return res;
}

T cnt(int n, bool reverse) {
    T res = 0;
    for (int i = 1; i <= n; ++i) {
        if (reverse) {
            res += binPow(nums[n - i], i);
        } else {
            res += binPow(nums[i - 1], i);
        }
        res %= MOD;
    }

    return res;
}

void upsideDown(int n) {
    for (int i = 0; i < n; ++i) {
        nums[i] = n - nums[i] + 1;
    }
}

void makeRev(int n, bool reverse) {
    for (int i = 0; i < n; ++i) {
        if (reverse) {
            tmp[n - nums[i]] = n - i;
        } else {
            tmp[nums[i] - 1] = i + 1;
        }
    }
    swap(tmp, nums);
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int n, q;
    cin >> n >> q;
    for (int i = 0; i < n; ++i) {
        cin >> nums[i];
    }

    bool one = false, two = false, three = false;
    T normal = cnt(n, false), afterOne = cnt(n, true);
    upsideDown(n);
    T afterTwo = cnt(n, false);
    upsideDown(n);
    makeRev(n, false);
    T afterThree = cnt(n, false);
    makeRev(n, false);
    while (q--) {
        int b;
        cin >> b;
        if (b == 1) {
            one = !one;
        } else if (b == 2) {
            two = !two;
        } else {
            three = !three;
        }

        if (one) {
            cout << afterOne << ' ';
        } else if (two) {
            cout << afterTwo << ' ';
        } else if (three) {
            cout << afterThree << ' ';
        } else {
            cout << normal << ' ';
        }
    }
    cout << '\n';
    return 0;
}