#include <iostream>
#include <vector>
using namespace std;
#define ll long long
#define ld long double
const int MOD = 998244353;
ll binpow(ll x, ll n) {
	if (n == 0) return 1;
	if (n & 1) {
		ll cur = binpow(x, n - 1);
		return (cur * x) % MOD;
	}
	ll cur = binpow(x, n / 2);
	return (cur * cur) % MOD;
}
void solve() {
	int n, q; cin >> n >> q;
	vector <int> p(n);
	for (int i = 0; i < n; ++i) cin >> p[i];
	ll a1 = 0;
	for (int i = 0; i < n; ++i) {
		a1 += binpow(p[i], i + 1);
		a1 %= MOD;
	}
	vector <int> v(n);
	for (int i = 0; i < n; ++i) v[i] = p[n - 1 - i];
	p = v;
	ll a2 = 0;
	for (int i = 0; i < n; ++i) {
		a2 += binpow(p[i], i + 1);
		a2 %= MOD;
	}
	int s = 0;
	vector <int> ans;
	for (int i = 0; i < q; ++i) {
		int type; cin >> type;
		if (s == 0) {
			if (type != 3) s = 1;
		}
		else s = 0;
		if (s == 0) ans.push_back(a1);
		else ans.push_back(a2);
	}
	for (auto el : ans) cout << el << " ";
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	solve();
}
