#include <iostream>
#include <vector>
#include <algorithm>
#include <map>

using namespace std;

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

const ll MOD = 998244353;
ll ans[2][2][2];

ll bin_pow(ll a, ll b) {
	if (b == 0) {
		return 1;
	}

	if (b % 2 == 0) {
		return bin_pow((a * a) % MOD, b / 2);
	}

	return (a * bin_pow(a, b - 1)) % MOD;
}

int main() {
	ios_base::sync_with_stdio(false);
	cout.tie(0);
	cin.tie(0);

	int n, q;
	cin >> n >> q;

	vector<int> p(n);
	for (int i = 0; i < n; i++) {
		cin >> p[i];
	}

	for (int rev = 0; rev < 2; rev++) {
		for (int inv = 0; inv < 2; inv++) {
			for (int made = 0; made < 2; made++) {
				vector<int> tmp = p;

				if (rev) {
					reverse(tmp.begin(), tmp.end());
				}

				if (inv) {
					for (auto& i : tmp) {
						i = n - i + 1;
					}
				}

				if (made) {
					vector<int> know(n);
					for (int i = 0; i < n; i++) {
						know[tmp[i] - 1] = i + 1;
					}

					swap(know, tmp);
				}

				ll sm = 0;

				for (ll i = 0; i < n; i++) {
					sm = (sm + bin_pow(tmp[i], i + 1)) % MOD;
				}

				ans[rev][inv][made] = sm;
			}
		}
	}

	int cnt_inv = 0;
	int cnt_rev = 0;
	int cnt_made = 0;

	for (int i = 0; i < q; i++) {
		int b;
		cin >> b;

		if (b == 1) {
			if (cnt_made == 1) {
				cnt_inv++;
			}
			else {
				cnt_rev++;
			}
		}

		if (b == 2) {
			if (cnt_made == 1) {
				cnt_rev++;
			}
			else {
				cnt_inv++;
			}
		}

		cnt_rev %= 2;
		cnt_inv %= 2;

		if (b == 3) {
			cnt_made++;
		}

		cnt_made %= 2;

		cout << ans[cnt_rev][cnt_inv][cnt_made] << '\n';
	}


	return 0;
}