#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
using namespace std;
using ll = long long;

const ll mod = 998244353;

ll binpow(ll a, ll n) {
    ll res = 1;
    while (n) {
        if (n & 1) {
            res *= a;
            res %= mod;
        }
        n >>= 1;
        a *= a;
        a %= mod;
    }
    return res;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n, q;
    cin >> n >> q;
    vector<int> p(n), r(n);
    for (int i = 0; i < n; ++i) {
        cin >> p[i];
        r[p[i] - 1] = i + 1;
    }
    vector<ll> cost(4), cost2(4);
    for (int mask = 0; mask < 4; ++mask) {
        vector<int> a = p;
        if (mask & 1) {
            reverse(a.begin(), a.end());
        }
        if (mask & 2) {
            for (int i = 0; i < n; ++i) {
                a[i] = n - a[i] + 1;
            }
        }
        for (int i = 0; i < n; ++i) {
            cost[mask] += binpow(a[i], i + 1);
            cost[mask] %= mod;
        }
        a = r;
        if (mask & 1) {
            reverse(a.begin(), a.end());
        }
        if (mask & 2) {
            for (int i = 0; i < n; ++i) {
                a[i] = n - a[i] + 1;
            }
        }
        for (int i = 0; i < n; ++i) {
            cost2[mask] += binpow(a[i], i + 1);
            cost2[mask] %= mod;
        }
    }
    int mask = 0, mask2=0;
    while (q-- > 0) {
        int b;
        cin >> b;
        --b;
        if (b == 2) {
            swap(cost, cost2);
            swap(mask, mask2);
            cout << cost[mask] << '\n';
        } else {
            mask ^= (1<<b);
            mask2 ^= (1 << (b^1));
            cout << cost[mask] << '\n';
        }
    }
    return 0;
}