#include <iostream>
#include <vector>
#include <map>
#include <random>
#include <chrono>
using namespace std;
#define ll long long
#define ld long double
const int MOD = 998244353;
std::mt19937 rnd(std::chrono::high_resolution_clock::now().time_since_epoch().count());
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> op;
vector <int> v;
vector <int> p;
map <pair <int, int>, int> mp;

void solve() {
	cin >> n >> q;
	p.resize(n);
	for (int i = 0; i < n; ++i) cin >> p[i];
	vector <int> v = p;
	mp[{v[0], v.back()}] = get(v);
	for (int i = 0; i < 50; ++i) {
		int type = uniform_int_distribution <int>(1, 2) (rnd);
		if (type == 1) v = r(v);
		else v = pr(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)
			swap(f, l);
		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();
}
