#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<unordered_set>
using namespace std;
#define int long long
#define pb push_back
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define ff first
#define ss second
const int maxn = 1e5, mod = 998244353;
int n;
int sm(int a, int b) {
	if (a + b >= mod) return a + b - mod;
	return a + b;
}

int binpow(int x, int s) {
	if (!s) return 1;
	if (s % 2) return x * binpow(x, s - 1) % mod;
	int t = binpow(x, s / 2);
	return t * t % mod;
}

int calc(vector <int>& a) {
	int ans = 0;
	for (int i = 0; i < n; ++i)
		ans = sm(ans, binpow(a[i], i + 1));
	return ans;
}

void per(vector <int>& a) {
	for (int i = 0; i < n; ++i)
		a[i] = n - a[i] + 1;
}

void obr(vector <int>& a) {
	vector <int> q(n);
	for (int i = 0; i < n; ++i)
		q[a[i] - 1] = i + 1;
	swap(q, a);
}

void solve() {
	int q;
	cin >> n >> q;
	vector <int> p(n), a;
	for (int i = 0; i < n; ++i)
		cin >> p[i];
	vector <vector <int>> ans(2, vector <int>(2));
	for (int i = 0; i < 2; ++i) {
		for (int j = 0; j < 2; ++j) {
			if (i) reverse(all(p));
			if (j) per(p);
			ans[i][j] = calc(p);
			if (i) reverse(all(p));
			if (j) per(p);
		}
	}
	vector <int> t(3);
	while (q--) {
		int b;
		cin >> b;
		t[b] = !t[b];
		cout << ans[t[1]][t[2]] << "\n";

	}
}

signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int t = 1;
	//cin >> t;
	while (t--)
		solve();
}