#include <iostream>
#include <vector>
#include <map>
using namespace std;
#define ll long long
#define ld long double
const int MOD = 998244353;
ll binpow(ll x, ll n) {
	if (n == 0) return 1;
	if (n & 1) {
		ll cur = binpow(x, n - 1);
		return (cur * x) % MOD;
	}
	ll cur = binpow(x, n / 2);
	return (cur * cur) % MOD;
}
int n, q;
ll get(vector <int>& p) {
	ll ans = 0;
	for (int i = 0; i < n; ++i) {
		ans += binpow(p[i], i + 1);
		ans %= MOD;
	}
	return ans;
}
vector <int> r(vector <int>& p) {
	vector <int> q(n);
	for (int i = 0; i < n; ++i) q[i] = p[n - 1 - i];
	return q;
}
vector <int> pr(vector <int>& p) {
	vector <int> q(n);
	for (int i = 0; i < n; ++i) q[i] = n - p[i] + 1;
	return q;
}
vector <int> v(vector <int>& p) {
	vector <int> q(n);
	for (int i = 0; i < n; ++i) q[p[i] - 1] = i + 1;
	return q;
}
void solve() {
	cin >> n >> q;
	vector <int> p(n);
	for (int i = 0; i < n; ++i) cin >> p[i];
	map <pair <int, int>, int> mp;
	vector <int> v = p;
	mp[{v[0], v.back()}] = get(v);
	v = r(v);
	mp[{v[0], v.back()}] = get(v);
	v = pr(v);
	mp[{v[0], v.back()}] = get(v);
	v = p;
	v = pr(v);
	mp[{v[0], v.back()}] = get(v);
	v = r(v);
	mp[{v[0], v.back()}] = get(v);
	vector <int> ans;
	int f = p[0], l = p.back();
	for (int i = 0; i < q; ++i) {
		int type; cin >> type;
		if (type == 1) {
			int x = f;
			f = l;
			l = x;
		}
		else if (type == 2) {
			f = n + 1 - f;
			l = n + 1 - l;
		}
		ans.push_back(mp[{f, l}]);
	}
	for (auto el : ans) cout << el << " ";
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	solve();
}
