#include <iostream>
#include <vector>
#include <cmath>
#include <bitset>

using namespace std;

const long long mod = 998244353;

vector<int> reverse1(vector<int> &v) {
	int n = v.size();
	vector<int> ans(n);
	for (int i = 0; i < n; i++) {
		ans[i] = v[n - i - 1];
	}
	return ans;
}

vector<int> reverse2(vector<int>& v) {
	int n = v.size();
	vector<int> ans(n);
	for (int i = 0; i < n; i++) {
		ans[i] = n + 1 - v[i];
	}
	return ans;
}

vector<int> reverse3(vector<int>& v) {
	int n = v.size();
	vector<int> ans(n);
	for (int i = 0; i < n; i++) {
		ans[v[i] - 1] = i + 1;
	}
	return ans;
}

vector<vector<long long>> up;
int lg;

long long calc(vector<int>& v) {
	long long ans = 0;
	int n = v.size();
	for (int i = 0; i < n; i++) {
		int it = i + 1;
		long long res = 1;
		for (int j = lg - 1; j >= 0; j--) {
			if (it >= (1 << j)) {
				it -= (1 << j);
				res *= up[v[i] - 1][j];
				res %= mod;
			}
		}
		ans += res;
		ans = (ans < mod) ? ans : ans - mod;
	}
	return ans;
}

int main()
{
	int n, q; cin >> n >> q;
	vector<int> v(n);
	for (int i = 0; i < n; i++) {
		cin >> v[i];
	}
	int n1 = n; lg = 0;
	while (n1) {
		n1 = n1 >> 1;
		lg++;
	}
	up.assign(n, vector<long long> (lg));
	for (int i = 0; i < n; i++) {
		up[i][0] = i + 1;
		for (int j = 1; j < lg; j++) {
			up[i][j] = (up[i][j - 1] * up[i][j - 1]) % mod;
		}
	}
	int in;
	int number = 0;
	vector<int> ans(8);
	for (int i = 0; i < 8; i++) {
		vector<int> it = v;
		bitset<3> bts = i;
		if (bts[0]) {
			it = reverse1(it);
		}
		if (bts[1]) {
			it = reverse2(it);
		}
		if (bts[2]) {
			it = reverse3(it);
		}
		ans[i] = calc(it);
	}
	for (int w = 0; w < q; w++) {
		cin >> in;
		number = number ^ (1 << (in - 1));
		cout << ans[number] << ' ';
	}
}