#include <cstring>
#include <ext/pb_ds/assoc_container.hpp>
#include <fstream>
#include <iostream>
constexpr int kMod = 998244353;
inline int add(int x, int y) { return x + y >= kMod ? x + y - kMod : x + y; }
inline void Add(int &x, int y) { x = x + y >= kMod ? x + y - kMod : x + y; }
inline long long mul(int x, long long y) { return x * y % kMod; }
std::ifstream fin("noodle.in");
std::ofstream fout("noodle.out");
unsigned long long seed;
unsigned long long rd(unsigned long long &x) {
  x ^= (x << 13);
  x ^= (x >> 7);
  x ^= (x << 17);
  return x;
}
int test, n, q, x;
long long k_max;
int a[2000001], b[2000001];
long long iv2[501];
long long Ksm(long long a, long long b) {
  long long s = 1LL;
  while (b) {
    if (b & 1) s = s * a % kMod;
    a = a * a % kMod;
    b >>= 1;
  }
  return s;
}
namespace subtask1 {
int ans[505];
void Solve() {
  ans[0] = a[x];
  // for (int i = 1; i <= n; i++) std::cerr << a[i] << " \n"[i == n];
  for (int rnd = 1; rnd <= k_max; rnd++) {
    for (int i = 1; 2 * i <= n; i++)
      b[2 * i - 1] = b[2 * i] = add(a[i], a[n - i + 1]);
    std::memcpy(a + 1, b + 1, 4 * n);
    ans[rnd] = a[x];
    // for (int i = 1; i <= n; i++) std::cerr << a[i] << " \n"[i == n];
  }
  long long Ans = 0LL;
  for (int i = 1; i <= q; i++) {
    long long k = rd(seed) % k_max;
    Ans ^= i * mul(ans[k], iv2[k]);
  }
  std::cout << Ans << '\n';
}
}  // namespace subtask1
namespace subtask2 {
long long ans[31];
void Solve() {
  ans[0] = a[x];
  // for (int i = 1; i <= n; i++) std::cerr << a[i] << " \n"[i == n];
  for (int rnd = 1; rnd <= 30; rnd++) {
    for (int i = 1; 2 * i <= n; i++)
      b[2 * i - 1] = b[2 * i] = mul(add(a[i], a[n - i + 1]), 499122177LL);
    std::memcpy(a + 1, b + 1, 4 * n);
    ans[rnd] = a[x];
    // for (int i = 1; i <= n; i++) std::cerr << a[i] << " \n"[i == n];
  }
  long long Ans = 0LL;
  for (int i = 1; i <= q; i++) {
    long long k = rd(seed) % k_max;
    k = std::min(k, 30LL);
    Ans ^= i * ans[k];
  }
  std::cout << Ans << '\n';
}
}  // namespace subtask2
namespace subtask3 {
long long ans[31];
class Matrix {
 public:
  Matrix() { std::memset(a_, 0, sizeof(a_)); }
  int *operator[](std::size_t x) { return a_[x]; }
  const int *operator[](std::size_t x) const { return a_[x]; }
  Matrix operator*(const Matrix &rhs) const {
    Matrix s;
    for (int i = 0; i < 2; i++)
      for (int k = 0; k < 2; k++)
        if (a_[i][k])
          for (int j = 0; j < 2; j++) Add(s[i][j], mul(a_[i][k], rhs[k][j]));
    return s;
  }
  Matrix &operator*=(const Matrix &rhs) { return *this = *this * rhs; }
  Matrix Pow(long long b) {
    Matrix a = *this, s;
    s[0][0] = s[1][1] = 1;
    while (b) {
      if (b & 1) s *= a;
      a *= a;
      b >>= 1;
    }
    return s;
  }
  ~Matrix() {}

 private:
  int a_[2][2];
};
void Solve() {
  ans[0] = a[x];
  // for (int i = 1; i <= n; i++) std::cerr << a[i] << " \n"[i == n];
  for (int rnd = 1; rnd <= 30; rnd++) {
    for (int i = 1; 2 * i <= n; i++)
      b[2 * i - 1] = b[2 * i] = mul(add(a[i], a[n - i + 1]), 499122177LL);
    std::memcpy(a + 1, b + 1, 4 * n);
    ans[rnd] = a[x];
    // for (int i = 1; i <= n; i++) std::cerr << a[i] << " \n"[i == n];
  }
  long long Ans = 0LL;
  Matrix ini, tran;
  ini[0][0] = a[1], ini[0][1] = a[n];
  tran[0][0] = tran[1][0] = 499122177, tran[0][1] = 1;
  int lim = 2 * n / 3;
  for (int i = 1; i <= q; i++) {
    long long k = rd(seed) % k_max;
    if (k <= 30) {
      Ans ^= i * ans[k];
    } else {
      k -= 30;
      Matrix res = ini * tran.Pow(k);
      long long as = x <= lim ? res[0][0] : res[0][1];
      Ans ^= i * as;
    }
  }
  std::cout << Ans << '\n';
}
}  // namespace subtask3
namespace subtask4 {
class Matrix {
 public:
  Matrix() { std::memset(a_, 0, sizeof(a_)); }
  int *operator[](std::size_t x) { return a_[x]; }
  const int *operator[](std::size_t x) const { return a_[x]; }
  Matrix operator*(const Matrix &rhs) const {
    Matrix s;
    for (int i = 1; i <= n; i++)
      for (int k = 1; k <= n; k++)
        if (a_[i][k])
          for (int j = 1; j <= n; j++) Add(s[i][j], mul(a_[i][k], rhs[k][j]));
    return s;
  }
  Matrix &operator*=(const Matrix &rhs) { return *this = *this * rhs; }

 private:
  int a_[502][502];
};
void Solve() {
  Matrix ini, tran[65];
  for (int i = 1; i <= n; i++) ini[1][i] = a[i];
  for (int i = 1; i <= n / 2; i++)
    tran[0][i][2 * i - 1] = tran[0][i][2 * i] = 499122177;
  for (int i = n / 2 + 1; i <= n; i++)
    tran[0][i][2 * n - 2 * i + 1] = tran[0][i][2 * n - 2 * i + 2] = 499122177;
  for (int i = 1; i <= 62; i++) tran[i] = tran[i - 1] * tran[i - 1];
  long long Ans = 0LL;
  for (int i = 1; i <= q; i++) {
    long long k = rd(seed) % k_max;
    Matrix f = ini;
    for (int i = 0; i < 60; i++)
      if (k >> i & 1) f *= tran[i];
    Ans ^= i * (long long)f[1][x];
  }
  std::cout << Ans << '\n';
}
}  // namespace subtask4
void Solve() {
  std::cin >> n >> q >> x >> k_max;
  for (int i = 1; i <= n; i++) std::cin >> a[i];
  if (test <= 2) return subtask1::Solve();
  if (test == 3) return subtask2::Solve();
  if (test == 7) return subtask3::Solve();
  subtask4::Solve();
}
int main() {
  std::cin.rdbuf(fin.rdbuf()), std::cout.rdbuf(fout.rdbuf());
  iv2[0] = 1LL;
  for (int i = 1; i <= 500; i++) iv2[i] = iv2[i - 1] * 499122177 % kMod;
  int T;
  std::cin >> test >> T >> seed;
  while (T--) Solve();
  return 0;
}
