#include <iostream>
#include <algorithm>
#include <set>
#include <map>
#include <climits>
#include <unordered_map>
#include <unordered_set>
#include <cmath>
#include <vector>
#pragma GCC optimize("Ofast")
using namespace std;
using ll = long long;
using ld = long double;
const int maxn = 500'000, mod = 998'244'353;
ll calc(vector<int> &a) {
	ll ans = 0;
	for (int i = 0; i < a.size(); ++i) {
		ll cur = 1;
		for (int j = 0; j <= i; ++j) {
			cur = (cur * a[i]) % mod;
		}
		ans += cur;
	}
	return ans;
}
int main() {
	cin.tie(0)->sync_with_stdio(false);
	int n, q; cin >> n >> q;
	vector<int> a(n);
	for (int i = 0; i < n; ++i) cin >> a[i];
	for (int i = 0; i < q; ++i) {

		int cmd; cin >> cmd;
		if (cmd == 1) {
			reverse(a.begin(), a.end());
		}
		else if (cmd == 2) {
			vector<int> b(n);
			for (int i = 0; i < n; ++i) {
				b[i] = n - a[i] + 1;
			}
			swap(a, b);
		}
		else {
			vector<int> b(n);
			for (int i = 0; i < n; ++i) {
				b[a[i] - 1] = i + 1;
			}
			swap(a, b);
		}
		cout << calc(a) << ' ';
	}
}