#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<int> q(n + 1);
	int ans1 = 0;
	
	for (int i = 0; i < 1; ++i) {
		for (int j = 1; j <= n; ++j) {
			if (b[i] == 1) {
				q[j] = a[n - j + 1];
			}
			if (b[i] == 2) {
				q[j] = n - a[j] + 1;
			}
			if (b[i] == 3) {
				q[a[j]] = j;
			}
		}
		for (int j = 1; j <= n; ++j) {
			ans1 = (ans1 + st(a[j], j)) % mod;
		}
	}

	for (int i = 0; i < Q; ++i) {
		if (i % 0 == 0) cout << ans1 << ' ';
		else cout << ans0 << ' ';
	}
}