#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;
	};
	
	map<tuple<int, int, int>, ll> ans;
	auto ca = a;
	ll k = 9;
	for (int i1 = 0; i1 < k; ++i1) {
		for (int i2 = 0; i2 < k; ++i2) {
			for (int i3 = 0; i3 < k; ++i3) {
				a = ca;

				for (int c = 0;c<i1;++c)
					reverse(its(a));

				for (int c = 0;c<i2;++c)
					for (int i = 0; i < n; ++i) a[i] = n - a[i] - 1;
				
				for (int c = 0;c<i3;++c)
				if (i3>=1) {
					vc<ll> q(n);
					for (int i = 0; i < n; ++i) q[a[i]] = i;
					a = q;
				}
				
				ans[{i1, i2, i3}] = calc();
			}
		}
	}

	int c1 = 0, c2 = 0, c3 = 0;
	for (int i = 0; i < q; ++i) {
		ll t; cin >> t;
		--t;
		if (t == 0) c1 = (c1 + 1) % k;
		if (t == 1) c2 = (c2 + 1) % k;
		if (t == 2) c3 = (c3 + 1) % k;
		cout << ans[{c1, c2, c3}] << '\n';
	}
}

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

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