//#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;
}

ll arr[N];
ll tmp[N];
void solve() {
  ll n, q;
  cin >> n >> q;
  for (ll i = 0; i < n; ++i) cin >> arr[i];

  while (q--) {
    ll t;
    cin >> t;

    if (t == 1)
      for (ll i = 0; i < n / 2; ++i) swap(arr[i], arr[n - i - 1]);
    else if (t == 2)
      for (ll i = 0; i < n; ++i) arr[i] = n - arr[i] + 1;
    else {
      for (ll i = 0; i < n; ++i) tmp[arr[i] - 1] = i + 1;
      for (ll i = 0; i < n; ++i) arr[i] = tmp[i];
    }

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

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

  return 0;
}