#include<iostream>
#include<vector>
#include<set>
#include<map>
#include<stack>
#include<deque>
#include<iomanip>
#include<queue>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<bitset>
#include<cmath>
#include<algorithm>
#include<random>
#include<ctime>

#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx,avx2,bmi,popcnt")

#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
using uint = unsigned int;

mt19937 mt(time(0));
const int N = 1e5 + 2, mod = 998244353, inf = 1e9 + 100;
const ll llinf = 1e18 + 1000;
int add(int a, int b) {
	return a + b - mod * (a + b >= mod);
}
int bpowm(int a, int n) {
	return n == 0 ? 1 : n % 2 == 0 ? bpowm(1ll * a * a % mod, n / 2) : 1ll * a * bpowm(a, n - 1) % mod;
}
int n, q, a[8][N], ans[8];

void solve() {
	cin >> n >> q;
	for (int i = 0; i < n; ++i) cin >> a[0][i];
	for (int i = 0; i < n; ++i) {
		a[1][i] = a[0][n - i - 1];
	}
	for (int j = 0; j < 2; ++j) {
		for (int i = 0; i < n; ++i) {
			a[2 + j][i] = n + 1 - a[j][i];
		}
	}
	for (int j = 0; j < 4; ++j) {
		for (int i = 0; i < n; ++i) {
			a[4 + j][a[j][i] - 1] = i + 1;
		}
	}
	for (int j = 0; j < 8; ++j) {
		for (int i = 0; i < n; ++i) {
			ans[j] = add(ans[j], bpowm(a[j][i], i + 1));
		}
		cout << ans[j] << '\n';
	}
	int mask = 0;
	while (q--) {
		int c;
		cin >> c;
		if (c == 1) {
			if (mask & 4) mask ^= 2;
			else mask ^= 1;
		}
		else if (c == 2) {
			if (mask & 4) mask ^= 1;
			else mask ^= 2;
		}
		else {
			mask ^= 4;
		}
		cout << ans[mask] << ' ';
	}
}

signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int tt = 1;
	//cin >> tt;
	while (tt--) {
		solve();
		cout << '\n';
		cout.flush();
	}
	return 0;
}