#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <cmath>
using namespace std;

#define ll long long
#define vc vector
#define db double
#define str string
#define its(a) (a).begin(), (a).end()
#define itsr(a) (a).rbegin(), (a).rend()
#define sz(a) (a).size()
#define tstr to_string
#define scan(a) for (auto &_i:a) cin >> _i;

const ll MOD = 998244353;

ll binpow(ll a, ll k) {
	if (k == 0) return 1;
	if (k == 1) return a;
	ll md = binpow(a, k / 2);
	if (k % 2) return md * md % MOD * a % MOD;
	return md * md % MOD;
}


void solve() {
	/*vc<ll> tr;
	auto get = [&](auto get, int v, int l, int r, int lq, int rq) -> ll {
		if (lq <= l and r <= rq) return tr[v];
		if (rq <= l or r <= lq) return 0;
		int mid = (r + l) >> 1;
		return get(get, 2 * v + 1, l, mid, lq, rq) + get(get, 2 * v + 2, mid, r, lq, rq);
	};
	auto build = [&](auto build, int v, int l, int r) -> void {
		if (r - l == 1) {
			tr[v] = a[l];
			return;
		}
		int mid = (r + l) >> 1;
		build(build, 2 * v + 1, l, mid);
		build(build, 2 * v + 2, mid, r);
		tr[v] = tr[2 * v + 1] + tr[2 * v + 2];
	};
	auto st = [&](auto st, int v, int l, int r, int e, int x) -> void {
		if (r - l == 1) {
			tr[v] = x;
			return;
		}
		int mid = (r + l) >> 1;
		if (e < mid) st(st, 2 * v + 1, l, mid, e, x);
		else st(st, 2 * v + 2, mid, r, e, x);
		tr[v] = tr[2 * v + 1] + tr[2 * v + 2];
	};*/
	ll n, q; cin >> n >> q;
	vc<ll> a(n); scan(a);
	for (auto& i : a) --i;
	auto calc = [&]()->ll {
		ll ans = 0;
		for (int i = 0; i < n; ++i) {
			ans += binpow(a[i]+1, i + 1);
			
		}
		ans %= MOD;
		return ans;
	};
	
	vc<ll> ans(8);
	auto ca = a;
	for (int msk = 0; msk < (1 << 3); ++msk) {
		a = ca;

		if (msk&1) reverse(its(a));
		if ((msk>>1)&1) {
			for (int i = 0; i < n; ++i) a[i] = n - a[i] - 1;
		}
		if ((msk>>2)&1) {
			vc<ll> q(n);
			for (int i = 0; i < n; ++i) q[a[i]] = i;
			a = q;
		}
		ans[msk] = calc();
	}

	int msk = 0;
	for (int i = 0; i < q; ++i) {
		ll t; cin >> t;
		--t;
		msk ^= (1 << t);
		cout << ans[msk] << '\n';
	}
}

int main()
{
	cin.tie(0)->sync_with_stdio(0);

	ll _t = 1;
	//cin >> _t;
	while (_t--)
		solve();
}
