#include <bits/stdc++.h>

using namespace std;

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

const int MOD = 998244353;
const int Inf = 2e9;
const ll INF = 3e18;

int binpow(int a, int b) {
  if (b == 0) return 1;
  ll k = binpow(a, b/2);
  if (b % 2 == 0) return k * k % MOD;
  else return k * k % MOD * a % MOD;
}

int32_t main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n, q;
  cin >> n >> q;
  vector <int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i]; a[i]--;
  }
  auto calc = [&]() {
    int ans = 0;
    for (int i = 0; i < n; i++) {
      ans = (ans + binpow(a[i] + 1, i + 1)) % MOD;
    }
    return ans;
  };
  while (q--) {
    int t;
    cin >> t;
    if (t == 1) {
      reverse(a.begin(), a.end());
    } else if (t == 2) {
      for (int i = 0; i < n; i++) {
        a[i] = n - a[i] - 1;
      }
    } else {
      vector <int> b(n);
      for (int i = 0; i < n; i++) {
        b[a[i]] = i;
      }
    }
    cout << calc() << ' ';
  }
  return 0;
}