//#pragma GCC optimize("O3", "unroll-loops")

#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>

//#pragma GCC target("avx2")

using namespace std;
//using namespace __gnu_pbds;

using ll = long long;
template <int N, class T = ll>
using pii = array<T, N>;
//using oset = tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update>;

#ifdef LOCAL
ifstream iss32("in.txt");
#define cin iss32
#endif

constexpr ll N = 2e5 + 15;

constexpr ll md = 998244353;
ll bp(ll x, ll n) {
  ll ans = 1;
  while (n) {
    if (n & 1) ans = (ans * x) % md;

    n >>= 1;
    x = (x * x) % md;
  }
  return ans;
}

vector<ll> arr;
vector<ll> tmp;

ll sm[8];

void solve() {
  ll n, q;
  cin >> n >> q;

  arr.resize(n);
  tmp.resize(n);
  for (ll i = 0; i < n; ++i) cin >> arr[i];

  for (ll i = 0; i < n; ++i) sm[0] += bp(arr[i], i + 1);
  sm[0] %= md;

  for (ll i = 0; i < n; ++i) tmp[arr[i] - 1] = i + 1;

  for (ll i = 1; i < 8; ++i) {
    if (i & 4) swap(arr, tmp);
    if (i & 1) reverse(arr.begin(), arr.end());
    if (i & 2) for (ll j = 0; j < n; ++j) arr[j] = n - arr[j] + 1;

    for (ll j = 0; j < n; ++j) sm[i] += bp(arr[j], j + 1);
    sm[i] %= md;

    if (i & 2) for (ll j = 0; j < n; ++j) arr[j] = n - arr[j] + 1;
    if (i & 1) reverse(arr.begin(), arr.end());
    if (i & 4) swap(arr, tmp);
  }

  ll xr = 0;
  while (q--) {
    ll t;
    cin >> t;

    if (t == 3) {
      xr ^= 4;
      xr = xr - (xr & 2) + (xr & 2 >> 1) - (xr & 1) + (xr & 1 << 1);
    }
    else xr ^= (1ll << --t);

    //cerr << xr << ' ' << sm[xr] << endl;
    cout << sm[xr] << ' ';
  }
}

int main() {
  ll t = 1;
  //cin >> t;
  while (t--) solve();

  return 0;
}