#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using ull = unsigned long long;
using db = double;
using ldb = long double;

#pragma GCC optimize("O3,fast-math,unroll-loops")

const int mod = 998244353;

struct hash_t{
	int v1;
	ull v2;

	hash_t() {
		v1 = v2 = 0;
	}

	hash_t(int _v1, ull _v2) {
		v1 = _v1;
		v2 = _v2;
	}

	hash_t operator+(const hash_t& h) const {
		hash_t res = hash_t(v1 + h.v1, v2 + h.v2);
		if (res.v1 >= mod) res.v1 -= mod;
		return res;
	}

	hash_t operator-(const hash_t& h) const {
		hash_t res = hash_t(v1 - h.v1, v2 - h.v2);
		if (res.v1 < 0) res.v1 += mod;
		return res;
	}

	hash_t operator*(const hash_t& h) const {
		return hash_t(1ll * v1 * h.v1 % mod, v2 * h.v2);
	}
};

ll bin_pow(int x, int pow) {
	if (pow == 0) return 1;
	if ((pow & 1) == 0) {
		ll res = bin_pow(x, pow / 2);
		return res * res % mod;
	} else {
		return bin_pow(x, pow - 1) * x % mod;
	}
}


vector<set<int>> g;

void euler(int v) {
	while (!g[v].empty()) {
		int to = *g[v].begin();
		g[v].erase(g[v].begin());
		g[to].erase(v);
		euler(to);
	}
	cout << v << ' ';
}


int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);

	int n, q;
	cin >> n >> q;
	vector<int> p(n);

	for (int i = 0; i < n; i++) {
		cin >> p[i];
	}

	ll sum = 0, sum1 = 0, sum2 = 0, sum3 = 0, sum4 = 0, sum5 = 0, sum6 = 0, sum7 = 0;

	for (int i = 0; i < n; i++) {
		sum = (sum + bin_pow(p[i], (i + 1))) % mod;
		sum1 = (sum1 + bin_pow(p[i], (n - i))) % mod;
		sum2 = (sum2 + bin_pow(n - p[i] + 1, (i + 1))) % mod;
		sum3 = (sum3 + bin_pow(i + 1, p[i])) % mod;

		sum4 = (sum4 + bin_pow(n - p[i] + 1, (n - i))) % mod;
		sum5 = (sum5 + bin_pow((n - i), p[i])) % mod;
		sum6 = (sum6 + bin_pow(i + 1, n - p[i] + 1)) % mod;
		sum7 = (sum7 + bin_pow((n - i), n - p[i] + 1)) % mod;
	}

	int cnt1 = 0, cnt2 = 0, cnt3 = 0;
	for (int i = 0; i < q; i++) {
		int b; cin >> b;
		if (b == 1) cnt1 = (cnt1 + 1) % 2;
		if (b == 2) cnt2 = (cnt2 + 1) % 2;
		if (b == 3) cnt3 = (cnt3 + 1) % 2;
		if (cnt1 == 0 && cnt2 == 0 && cnt3 == 0) {
			cout << sum;
		} else if (cnt1 == 1 && cnt2 == 0 && cnt3 == 0) {
			cout << sum1;
		} else if (cnt1 == 0 && cnt2 == 1 && cnt3 == 0) {
			cout << sum2;
		} else if (cnt1 == 0 && cnt2 == 0 && cnt3 == 1) {
			cout << sum3;
		} else if (cnt1 == 1 && cnt2 == 1 && cnt3 == 0) {
			cout << sum4;
		} else if (cnt1 == 1 && cnt2 == 0 && cnt3 == 1) {
			cout << sum5;
		} else if (cnt1 == 0 && cnt2 == 1 && cnt3 == 1) {
			cout << sum6;
		} else {
			cout << sum7;
		}
		cout << ' ';
	}

	return 0;
}
