// cf: stupid_moron
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
const int inf = 1e9 + 2145;
mt19937 rng(time(0));

const int mod = 998244353;
const int N = 1e5 + 21;
int n, q, p[N], b[N], ans[N];
int pw[N][16];

int add(int a, int b) {
	int c = a + b;
	while (c >= mod) c -= mod;
	while (c < 0) c += mod;
	return c;
}

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

int modpow(int a, int b) {
	int r = 1;
	while (b) {
		if (b & 1) r = mul(r, a);
		a = mul(a, a);
		b >>= 1;
	}
	return r;
}

void solve() {
	cin >> n >> q;
	for (int i = 0; i < n; i++)
		cin >> p[i];
	for (int i = 0; i < q; i++)
		cin >> b[i];

	for (int i = 0; i < n; i++) {
		vector<int> vc = {p[i], n - p[i] + 1, 
			i + 1, n - i};
		for (int j = 0; j < 4; j++) {
			for (int k = 0; k < 4; k++) {
				pw[i][j * 4 + k] = modpow(vc[j], vc[k]); 
			}
		}
	}

	int bt[8], et[8];
	for (int s = 0; s < 8; s++) {
		int X = s & 1;
		int F1 = (s >> 1) & 1;
		int F2 = (s >> 2) & 1;
		if (!X) {
			bt[s] = F1 ? 1 : 0;
			et[s] = F2 ? 3 : 2;
		} else {
			bt[s] = F1 ? 3 : 2;
			et[s] = F2 ? 1 : 0;
		}
	}

	for (int i = 0; i < n; i++)
	for (int s = 0; s < 8; s++)
		ans[s] = add(ans[s], pw[i][bt[s] * 4 + et[s]]);

	int s = 0;
	for (int i = 0; i < q; i++) {
		if (b[i] == 1) {
			s ^= 4;
		} else if (b[i] == 2) {
			s ^= 2;
		} else {
			int X = s & 1;
			int F1 = (s >> 1) & 1;
			int F2 = (s >> 2) & 1;
			s = (X ^ 1) | (F2 << 1) | (F1 << 2);
		}

		cout << ans[s] << ' ';
	}
}

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

	int t = 1;
	// cin >> t;

	while (t--) {
		solve();
	}

	return 0;
}