#include <iostream>
#include <algorithm>
#include <set>
#include <map>
#include <climits>
#include <unordered_map>
#include <unordered_set>
#include <cmath>
#include <vector>
#pragma GCC optimize("Ofast")
using namespace std;
using ll = long long;
using ld = long double;
const int maxn = 5'000, mod = 998'244'353;
ll pv[maxn][maxn];
ll pp(ll val, ll pp1) {
	ll ans = 1;
	ll start = val;
	while (pp1 != 1) {
		if (pp1 % 2 == 1) {
			ans = (ans * start) % mod;
			pp1--;
		}
		else {
			start = (start * start) % mod;
			pp1 /= 2;
		}
	}
	ans = (ans * start) % mod;
	return ans;
}
ll calc(vector<ll> &a) {
	ll ans = 0;
	for (int i = 0; i < a.size(); ++i) {
		ll cur = pp(a[i], i+1);
		ans = (ans +cur) % mod;
	}
	return ans;
}
int main() {
	cin.tie(0)->sync_with_stdio(false);
	ll n, q; cin >> n >> q;
	vector<ll> a(n);
	for (int i = 0; i < n; ++i) cin >> a[i];
	/*int cmd; cin >> cmd;
	ll ans2 = calc(a);
	ll ans1;
	if (cmd == 1) {
		reverse(a.begin(), a.end());
		ans1 = calc(a);
	}
	else if (cmd == 2) {
		vector<ll> b(n);
		for (int i = 0; i < n; ++i) {
			b[i] = n - a[i] + 1;
		}
		swap(a, b);
		ans1 = calc(a);
	}
	else {
		vector<ll> b(n);
		for (int i = 0; i < n; ++i) {
			b[a[i] - 1] = i + 1;
		}
		swap(a, b);
		ans1 = calc(a);
	}
	for (int i = 0; i < q; ++i) {
		if (i % 2 == 0) {
			cout << ans1;
		}
		else {
			cout << ans2;
		}
		cout << ' ';
	}
	return 0;*/
	map<pair<int, int>, int> cc;
	ll ans = calc(a);
	cc[{0, 0}] = ans;
	if (1) {
		reverse(a.begin(), a.end());
		ans = calc(a);
		cc[{1, 0}] = ans;
		reverse(a.begin(), a.end());
	}
	if (1) {
		vector<ll> b(n);
		for (int i = 0; i < n; ++i) {
			b[i] = n - a[i] + 1;
		}
		swap(a, b);
		ans = calc(a);
		cc[{0, 1}] = ans;
		reverse(a.begin(), a.end());
		ans = calc(a);
		cc[{1, 1}] = ans;
	}
	int p1 = 0, p2 = 0;
	for (int i = 0; i < q; ++i) {
		int cmd; cin >> cmd;
		if (cmd == 1) {
			p1 = (p1 + 1) % 2;
		}
		else {
			p2 = (p2 + 1) % mod;
		}
		cout << cc[make_pair(p1, p2)] << '\n';
	}
}