#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <random>
#include <ctime>
#include <stack>
#include <deque>
#include <queue>
#include <climits>
#include <cmath>
using namespace std;
#define all(a) (a).begin(), (a).end()
#define mid (l + r) / 2
//#define int long long

constexpr int mod = 998'244'353;
int add(int a, int b) {
    return ((a + b < mod) ? (a + b) : (a + b - mod));
}

int sub(int a, int b) {
    return ((a < b) ? (a + mod - b) : (a - b));
}

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

int binpow(int a, int v) {
    if (v == 0) return 1;
    if (v == 1) return a;
    if (v % 2 == 0) {
        return binpow(mul(a, a), v / 2);
    }
    return mul(a, binpow(a, v - 1));
}

void solve() {
    int n, q; cin >> n >> q;
    vector<int> p;
    bool is1 = false;
    bool is2 = false;
    bool is3 = false;
    for (int i = 0; i < n; i++) {
        int x; cin >> x;
        p.push_back(x);
    }
    int ans000 = 0;
    for (int j = 0; j < n; j++) {
        ans000 = add(ans000, binpow(p[j], j + 1));
    }
    vector<int> Q(n);
    for (int j = 0; j < p.size(); j++) {
        Q[p[j] - 1] = j + 1;
    }
    int ans001 = 0;
    for (int j = 0; j < n; j++) {
        ans001 = add(ans001, binpow(Q[j], j + 1));
    }
    int ans010 = 0;
    for (int j = 0; j < n; j++) {
        ans010 = add(ans010, binpow(n + 1 - p[j], j + 1));
    }
    int ans100 = 0;
    reverse(all(p));
    for (int j = 0; j < n; j++) {
        ans100 = add(ans100, binpow(p[j], j + 1));
    }
    int ans110 = 0;
    for (int j = 0; j < n; j++) {
        ans110 = add(ans110, binpow(n + 1 - p[j], j + 1));
    }
    for (int i = 0; i < q; i++) {
        int x; cin >> x;
        if (x == 1) {
            is1 = true - is1;
        }
        if (x == 2) {
            is2 = true - is2;
        }
        if (x == 3) {
            is3 = true - is3;
        }
        if (!is1 && !is2 && !is3) cout << ans000 << ' ';
        if (!is1 && !is2 && is3) cout << ans001 << ' ';
        if (is1 && !is2 && !is3) cout << ans100 << ' ';
        if (!is1 && is2 && !is3) cout << ans010 << ' ';
        if (is1 && is2 && !is3) cout << ans110 << ' '; 
    }
    cout << '\n';
}

signed main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int t = 1;
    //cin >> t;
    while (t--) {
        solve();
    }
}
