#define _CRT_SECURE_NO_WARNINGS


#include <iostream>
#include <algorithm>
#include <cmath>
#include <math.h>
#include <string>
#include <vector>

using namespace std;
using ll=long long;
const ll inf = 1e18;
const ll mod = 998244353;


ll p[100001];
ll t[100001];
ll b[100001];
ll res[100001];

ll st(ll x, ll y) {
	if (y == 0) {
		return 1;
	}
	if (y == 1) {
		return x;
	}
	ll h = st(x, y / 2);
	if (y % 2 == 0) {
		return (h * h) % mod;
	}
	else {
		return (((h * h) % mod) * x) % mod;
	}
}
int main() {
#ifdef _DEBUG
	freopen("in.txt", "r", stdin);
#endif
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	ll n, q;
	cin >> n >> q;
	for (int i = 1; i <= n; ++i) {
		cin >> p[i];
	}
	for (int i = 1; i <= n; ++i) {
		res[0] += st(p[i], i);
		res[0] %= mod;
	}
	for (int i = 1; i <= q; ++i) {
		cin >> b[i];
		ll ff = 0;
		for (int j = 1; j * 2 <= i; ++j) {
			ll fl = 0;
			for (int e = i - 2 * j + 1; e <= i - j; ++e) {
				if (b[e] != b[e + j]) {
					++fl;
				}
			}
			if (fl == 0) {
				cout << res[i - 2 * j] << "\n";
				++ff;
				break;
			}
		}
		if (ff == 0) {
			if (b[i] == 1) {
				for (int j = 1; j <= n; ++j) {
					t[j] = p[n + 1 - j];
				}
			}
			if (b[i] == 2) {
				for (int j = 1; j <= n; ++j) {
					t[j] = n - p[j] + 1;
				}
			}
			if (b[i] == 3) {
				for (int j = 1; j <= n; ++j) {
					t[p[j]] = j;
				}
			}
			for (int j = 1; j <= n; ++j) {
				p[j] = t[j];
			}
			ll res = 0;
			for (int j = 1; j <= n; ++j) {
				res += st(p[j], j);
				res %= mod;
			}
			cout << res << "\n";
		}
	}
}