#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> a(n), b(q);

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

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

	ll sum1 = 0, sum2 = 0;
	for (int i = 0; i < n; i++) {
		sum1 += bin_pow(a[i], (i + 1));
		sum1 %= mod;

		sum2 += bin_pow(a[n - i - 1], (i + 1));
		sum2 %= mod;
	}

	bool cur = 0;
	for (int i = 0; i < q; i++) {
		if (b[i] != 3) cur = !cur;

		if (cur) cout << sum2;
		else cout << sum1;
		cout << ' ';
	}
	return 0;
}
