#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <iomanip>
#include <deque>
#include <queue>
#include <numeric>
#include <algorithm>
#include <cmath>
#include <ctime>
#include <random>
using namespace std;

#define ll long long
#define ld long double
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
mt19937 rnd(time(0));

const int MOD = 998244353;


int bin_pow(int x, int y) {
	if (y == 0) return 1;
	if (y % 2 == 0) {
		int b = bin_pow(x, y / 2);
		return 1ll * b * b % MOD;
	}
	else {
		return 1ll * x * bin_pow(x, y - 1) % MOD;
	}
}

int add(int a, int b) {
	a += b;
	if (a >= MOD) {
		a -= MOD;
	}
	return a;
}

int n;
vector<int> p;
vector<int> q;
int ans;
void type_1() {
	for (int i = 0; i < n; i++) {
		q[i] = p[n - i - 1];
	}
	swap(q, p);
}
void type_2() {
	for (int i = 0; i < n; i++) {
		q[i] = n - p[i] - 1;
	}
	swap(q, p);
}
void type_3() {
	for (int i = 0; i < n; i++) {
		q[p[i]] = i;
	}
	swap(q, p);
}

void get(int t) {
	if (t == 1) type_1();
	if (t == 2) type_2();
	if (t == 3) type_3();
}

void get_ans() {
	ans = 0;
	for (int i = 0; i < n; i++) {
		ans = add(ans, bin_pow(p[i] + 1, i + 1));
	}
}
void solve() {
	int m;
	cin >> n >> m;
	p.assign(n, 0);
	q.assign(n, 0);
	for (int i = 0; i < n; i++) {
		cin >> p[i];
		p[i]--;
	}
	int an[2][2][2];
	vector<int> start = p;
	for (int i = 0; i < 2; i++) {
		for (int j = 0; j < 2; j++) {
			for (int v = 0; v < 2; v++) {
				p = start;
				if (i) get(1);
				if (j) get(2);
				if (v) get(3);
				get_ans();
				an[i][j][v] = ans;
			}
		}
	}
	vector<int> cnt(3);
	while (m--) {
		int h;
		cin >> h;
		h--;
		cnt[h]++;
		cnt[h] %= 2;
		cout << an[cnt[0]][cnt[1]][cnt[2]] << " ";
	}
}

signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	solve();
}