#include <iostream>
#include <vector>
#define int long long

using namespace std;

const int mod = 998244353;

int st(int a, int n) {
	int ans = 1;
	for (; n > 0; n = (n >> 1), a = a * a % mod) {
		if (n & 1) {
			ans = ans * a % mod;
		}
	}
	return ans;
}

signed main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int n, Q;
	cin >> n >> Q;
	vector<int> a(n + 1), b(Q);
	for (int i = 1; i <= n; ++i) cin >> a[i];
	for (int i = 0; i < Q; ++i) cin >> b[i];
	int ans0 = 0;
	for (int j = 1; j <= n; ++j) {
		ans0 = (ans0 + st(a[j], j)) % mod;
	}

	
	vector<vector<int>> ANS(2, vector<int>(2, -1));
	ANS[0][0] = ans0;
	vector<int> kol(2);
	
	for (int i = 0; i < Q; ++i) {
		if (b[i] == 1) kol[0]++;
		else kol[1]++;
		if (ANS[kol[0] % 2][kol[1] % 2] == -1) {
			vector<int> q(n + 1);
			if (kol[0] % 2 == 1) {
				for (int j = 1; j <= n; ++j) {
					q[j] = a[n - j + 1];
				}
			}
			vector<int> ap = q;
			if (kol[1] % 2 == 1) {
				for (int j = 1; j <= n; ++j) {
					q[j] = n - ap[j] + 1;
				}
			}
			int ansp = 0;
			for (int j = 1; j <= n; ++j) {
				ansp = (ansp + st(q[j], j)) % mod;
			}
			ANS[kol[0] % 2][kol[1] % 2] = ansp;
		}
		cout << ANS[kol[0] % 2][kol[1] % 2] << ' ';
	}

}