#include <bits/stdc++.h>

#define all(x) x.begin(), x.end()
#define debout(x) std::cout << #x << " : " << x << '\n';
#define debvout(x) std::cout << #x << " : "; for (auto i: x) std::cout << i << ' '; std::cout << '\n';
using ll = long long;

const ll mod = 998244353;

ll bin_pow(ll a, ll n) {
  ll res = 1;
  while (n > 0) {
    if (n & 1) (res *= a) %= mod, n--;
    (a *= a) %= mod, n >>= 1;
  }
  return res;
}

void s1nm() {
  ll n, q;
  std::cin >> n >> q;
  std::vector<ll> a(n);
  for (ll &i: a) std::cin >> i;
  ll ans1 = 0;
  for (ll i = 0; i < n; i++) (ans1 += bin_pow(a[i], i + 1)) %= mod;
  char t;
  std::cin >> t;
  std::vector<ll> b(n);
  if (t == '1') {
      for (ll i = 0; i < n; i++) b[i] = a[n - i - 1];
  } else if (t == '2') {
    for (ll i = 0; i < n; i++) b[i] = n - a[i] + 1;
  } else {
    for (ll i = 0; i < n; i++) b[a[i] - 1] = i + 1;
  }
  ll ans2 = 0;
  a = b;
  for (ll i = 0; i < n; i++) (ans2 += bin_pow(a[i], i + 1)) %= mod;
  for (ll i = 0; i < q; i++) std::cout << (i % 2 == 0 ? ans2 : ans1) << ' ';
}

signed main() {
  std::ios::sync_with_stdio(false), std::cin.tie(nullptr);
  ll TTT = 1;
  // std::cin >> TTT;
  while (TTT--) {
    s1nm();
    std::cout << '\n';
  }
}