#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
#define ll long long
#define ld long double
#define con continue
#define al(a) a.begin(), a.end()
#define size(a) a.size()

ll mod = 998244353;

vector<int> raz(vector<int> p) {
	int n = size(p);
	vector<int> q(n);
	for (int i = 0; i < n; i++) {
		q[i] = p[n - i - 1];
	}
	return q;
}

vector<int> per(vector<int> p) {
	int n = size(p);
	vector<int> q(n);
	for (int i = 0; i < n; i++) {
		q[i] = n - p[i] - 1;
	}
	return q;
}

vector<int> obr(vector<int> p) {
	int n = size(p);
	vector<int> q(n);
	for (int i = 0; i < n; i++) {
		q[p[i]] = i;
	}
	return q;
}

ll fp(ll n, ll b) {
	if (b == 0) {
		return 1;
	}
	if (b % 2 == 1) {
		return n * fp(n, b - 1) % mod;
	}
	ll t = fp(n, b / 2);
	return t * t % mod;
}

ll ans(vector<int>& p) {
	ll a = 0;
	for (int i = 1; i <= size(p); i++) {
		a += fp(p[i - 1] + 1, i);
		a %= mod;
	}
	return a;
}

int main() {
	int n, q;
	cin >> n >> q;
	vector<int> p(n);
	for (int i = 0; i < n; i++) {
		cin >> p[i];
		p[i]--;
	}
	for (int i = 0; i < q; i++) {
		int t;
		cin >> t;
		if (t == 1) {
			p = raz(p);
		}
		else if (t == 2) {
			p = per(p);
		}
		else {
			p = obr(p);
		}
		cout << ans(p) << ' ';
	}
}