// TaskB.cpp : This file contains the 'main' function. Program execution begins and ends there.
//

#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <set>
#include <map>

using namespace std;

using ll = long long;
using ld = long double;

const ll inf = 1e9 + 7;
const ll mod = 998244353;

ll binpow(ll a, ll p) {
	if (p == 0) {
		return 1;
	}
	if (p % 2 == 0) {
		ll tmp = binpow(a, p / 2);
		return tmp * tmp % mod;
	}
	else {
		return binpow(a, p - 1) * a % mod;
	}
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	ll n, q;
	cin >> n >> q;
	vector<ll> a(n);
	for (ll i = 0; i < n; i++) {
		cin >> a[i];
	}
	vector<ll> qs(q);
	ll ans = 0;
	for (ll i = 0; i < q; i++) {
		cin >> qs[i];
	}
	ll val1 = 0;
	ll val2 = 0;
	for (ll i = 0; i < n; i++) {
		val1 += binpow(a[i], i + 1);
		val2 += binpow(a[i], n - i);
		val1 %= mod;
		val2 %= mod;
	}
	for (ll i = 0; i < q; i++) {
		if (qs[i] != 3) {
			ans++;
		}
		if (ans % 2 == 0) {
			cout << val1 << '\n';
		}
		else {
			cout << val2 << '\n';
		}
	}
}
