#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <map>
#include <queue>
#include <iomanip>
#define int long long
using namespace std;

int mod = 998244353;

int bn(int a, int p) {
	if (p == 0) {
		return 1;
	}
	if (p % 2 == 0) {
		int T = bn(a, p / 2) % mod;
		return T * T % mod;
	}
	return bn(a, p - 1) * a % mod;
}

signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n, q; cin >> n >> q;

	vector<int> p(n);
	vector<int> b(q);
	for (int i = 0; i < n; i++) {
		cin >> p[i];
	}
	for (int i = 0; i < q; i++) {
		cin >> b[i];
		if (b[i] == 1) {
			reverse(p.begin(), p.end());
		}
		else if(b[i] == 2) {
			for (int j = 0; j < n; j++) {
				p[j] = n - p[j] + 1;
			}
		}
		else {
			for (int j = 0; j < n; j++) {
				p[p[j] - 1] = j + 1;
			}
		}
		int ans = 0;
		for (int j = 0; j < n; j++) {
			ans += bn(p[j], j + 1);
			ans %= mod;
		}
		cout << ans << ' ';
	}
} 