#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define int long long
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define F first
#define S second
#define Vector2 pair <int, int>
#define print(a) for (const auto& x : a) cout << x << ' ';

const int MOD = 998244353;
int nxt[8] = {2, 1, 4, 3, 6, 5, 8, 7};
int nxt2[8] = {3, 4, 1, 2, 7, 8, 5, 6};
int nxt3[8] = {5, 7, 6, 8, 1, 3, 2, 4};

int sum(int a, int b) {
	a += b;
	if (a >= MOD) {
		a -= MOD;
	}
	return a;
}

int binpow(int x, int pw) {
	//cout << x << ' ' << pw << endl;
	int res = 1;
	while (pw) {
		if (pw & 1) {
			(res *= x) %= MOD;
		}
		(x *= x) %= MOD;
		pw >>= 1;
	}
	return res;
}

void solve()
{
	int n, q;
	cin >> n >> q;
	vector <int> a(n);
	for (auto& x : a) {
		cin >> x;
	}
	vector <int> ans(8, 0);
	for (int i = 0; i < n; ++i) {
		int x[8] = {i + 1, n - i, i + 1, n - i, a[i], n - a[i] + 1, a[i], n - a[i] + 1};
		int pw[8] = {a[i], a[i], n - a[i] + 1, n - a[i] + 1, i + 1, i + 1, n - i, n - i};
		for (int j = 0; j < 8; ++j) {
			ans[j] = sum(ans[j], binpow(pw[j], x[j]));
		}
	}
	bool flag = true;
	int ptr = 0;
	while (q--) {
		int t;
		cin >> t;
		int sum = 0;
		if (t == 1) {
			ptr = nxt[ptr] - 1;
			cout << ans[ptr] << ' ';
		} else if (t == 2) {
			ptr = nxt2[ptr] - 1;
			cout << ans[ptr] << ' ';
		} else {
			ptr = nxt3[ptr] - 1;
			cout << ans[ptr] << ' ';
		}
	}
}

signed main()
{
	cin.tie(nullptr)->ios_base::sync_with_stdio(false);
	solve();
	return 0;
}