#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]--;
  }
  bool R = false;
  bool P = false;
  bool Q = false;
  map <array <bool, 3>, int> ans;
  auto calc = [&]() {
    int res = 0;
    for (int i = 0; i < n; i++) {
      res = (res + binpow(a[i] + 1, i + 1)) % MOD;
    }
    return res;
  };
  while (q--) {
    int t;
    cin >> t;
    if (t == 1) {
      R = !R;
      if (Q) P = !P;
    } else if (t == 2) {
      P = !P;
      if (!Q) R = !R;
    } else {
      Q = !Q;
    }
    if (ans.find({R, P, Q}) == ans.end()) {
      if (R) reverse(a.begin(), a.end());
      if (P) {
        for (int i = 0; i < n; i++) {
          a[i] = n - a[i] - 1;
        }
      }
      vector <int> cp = a;
      if (Q) {
        vector <int> b(n);
        for (int i = 0; i < n; i++) {
          b[a[i]] = i;
        }
        a = b;
      }
      ans[{R, P, Q}] = calc();
      if (R) reverse(a.begin(), a.end());
      if (P) {
        for (int i = 0; i < n; i++) {
          a[i] = n - a[i] - 1;
        }
      }
      if (Q) {
        a = cp;
      }
    }
    cout << ans[{R, P, Q}] << '\n';
  }
  return 0;
}