#include <bits/stdc++.h>

using namespace std;

#define ll long long

const ll mod = 998244353;

ll poww(ll x, ll p) {
  ll P[20];
  P[0] = 1;
  P[1] = x;
  for (int i = 2; i < 20; ++i) {
    P[i] = (P[i-1] * P[i-1]) % mod;
  }

  ll res = 1;
  for (int i = 0; i < 19; ++i) {
    if ((p >> i) & 1) {
      res = (res * P[i+1]) % mod;
    }
  }

  return res;
}

int main() {
  int n, q;
  cin >> n >> q;

  vector <int> p(n);
  for (int i = 0; i < n; ++i) {
    cin >> p[i];
  }

  ll s1 = 0;
  for (int j = 0; j < n; ++j) {
    s1 += poww(p[j], j+1);
    s1 %= mod;
  }

  int t;
  cin >> t;

  if (t == 1) {
    reverse(p.begin(), p.end());
  } else if (t == 2) {
    for (int j = 0; j < n; ++j) {
      p[j] = n-p[j]+1;
    }
  } else {
    vector <int> q(n);
    for (int j = 0; j < n; ++j) {
      q[p[j]-1] = j+1; 
    }
    p = q;
  }

  ll s2 = 0;
  for (int j = 0; j < n; ++j) {
    s2 += poww(p[j], j+1);
    s2 %= mod;
  }
  

  for (int i = 0; i < q; ++i) {
    if (i % 2 == 0) {
      cout << s2 << " ";
    } else {
      cout << s1 << " ";
    }
  }
  cout << "\n";

  return 0;
}
