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

using namespace std;

template<class T>
ostream& operator<<(ostream& out, vector<T> v) {
	for (T it : v) {
		out << it << ' ';
	}
	out << '\n';
	return out;
}

#define ll long long

const int MAX = 100'005;
const int MOD = 998'244'353;

ll mpow(ll a, ll x) {
	if (x == 0) {
		return 1;
	}
	if (x & 1) {
		return (a * mpow(a * a % MOD, x / 2)) % MOD;
	}
	return mpow(a * a % MOD, x / 2);
}
int a[MAX];
int b[MAX];
int q[MAX];
int n, m;

void f1() {
	reverse(a, a + n);
}
void f2() {
	for (int i = 0; i < n; i++) {
		a[i] = n - a[i] + 1;
	}
}
void f3() {
	for (int i = 0; i < n; i++) {
		q[a[i] - 1] = i + 1;
	}
	for (int i = 0; i < n; i++) {
		a[i] = q[i];
	}
}
ll get() {
	ll res = 0;
	for (int i = 0; i < n; i++) {
		res += mpow(a[i], i + 1);
		res %= MOD;
	}
	return res;
}
int main ()
{
	cin >> n >> m;

	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	for (int i = 0; i < m; i++) {
		cin >> b[i];
	}
	ll r1 = get();
	if (b[0] == 1) {
		f1();
	}
	else if (b[0] == 2) {
		f2();
	}
	else {
		f3();
	}
	ll r2 = get();
	for (int i = 0; i < m; i++) {
		if (i & 1) {
			cout << r1 << ' ';
		}
		else {
			cout << r2 << ' ';
		}
	}
}


