#include <bits/stdc++.h>

template<unsigned P>
class modint {
  using mint = modint<P>;

  unsigned v;

public:
  constexpr modint() : v() {}

  template<typename T,
           typename std::enable_if<std::is_integral<T>::value &&
                                       std::is_signed<T>::value,
                                   bool>::type = true>
  constexpr modint(T t_v) : v() {
    long long tmp = t_v;
    tmp %= P;
    if (tmp < 0) {
      tmp += P;
    }
    v = tmp;
  }

  template<typename T,
           typename std::enable_if<std::is_integral<T>::value &&
                                       std::is_unsigned<T>::value,
                                   bool>::type = true>
  constexpr modint(T t_v) : v() {
    v = t_v % P;
  }

  static constexpr unsigned mod() {
    return P;
  }

  constexpr unsigned val() {
    return v;
  }

  constexpr mint &operator+=(const mint &rhs) {
    v < P - rhs.v ? v += rhs.v : v -= P - rhs.v;
    return *this;
  }

  constexpr mint &operator-=(const mint &rhs) {
    v < rhs.v ? v += P - rhs.v : v -= rhs.v;
    return *this;
  }

  constexpr mint &operator*=(const mint &rhs) {
    v = (unsigned long long)(v) * rhs.v % P;
    return *this;
  }

  constexpr mint pow(unsigned long long b) const {
    mint a = *this, s = 1;
    while (b) {
      if (b & 1) {
        s *= a;
      }
      a *= a;
      b >>= 1;
    }
    return s;
  }

  constexpr mint inv() const {
    return pow(P - 2);
  }

  constexpr friend mint operator+(const mint &lhs, const mint &rhs) {
    return mint(lhs) += rhs;
  }

  constexpr friend mint operator-(const mint &lhs, const mint &rhs) {
    return mint(lhs) -= rhs;
  }

  constexpr friend mint operator*(const mint &lhs, const mint &rhs) {
    return mint(lhs) *= rhs;
  }

  constexpr friend bool operator==(const mint &lhs, const mint &rhs) {
    return lhs.v == rhs.v;
  }

  friend std::istream &operator>>(std::istream &in, mint &x) {
    return in >> x.v;
  }

  friend std::ostream &operator<<(std::ostream &out, const mint &x) {
    return out << x.v;
  }
};

using mint = modint<998244353>;

constexpr mint inv2 = mint(2).inv();

unsigned long long rd(unsigned long long &x) {
  x ^= (x << 13);
  x ^= (x >> 7);
  x ^= (x << 17);
  return x;
}

int main() {
  std::ifstream fin("noodle.in");
  std::ofstream fout("noodle.out");

  int test, T;
  unsigned long long seed;
  fin >> test >> T >> seed;
  while (T--) {
    int n, q, x;
    long long L;
    fin >> n >> q >> x >> L;
    --x;
    std::vector<mint> a(n);
    for (int i = 0; i < n; ++i) {
      fin >> a[i];
    }
    mint inv = mint(n / 2).inv();
    mint sum = std::accumulate(a.begin(), a.end(), mint());
    std::map<int, mint> mp;
    unsigned long long res = 0;
    for (int id = 1; id <= q; ++id) {
      long long k = rd(seed) % L;
      if (k == 0) {
        res ^= (unsigned long long)id * a[x].val();
        continue;
      }
      int px = x / 2, py = n - 1 - px;
      --k;
      int t = 2, r = 1;
      for (int i = 0; i < 60; ++i) {
        if (k >> i & 1) {
          r = 1ll * r * t % n;
        }
        t = 1ll * t * t % n;
      }
      mint ans = 0;
      if (mp.count(r)) {
        ans += mp[r];
      } else {
        for (int i = 0; i < r; ++i) {
          ans += a[(i * n + px) / r];
          ans += a[(i * n + py) / r];
        }
        mp[r] = ans;
      }
      ans += (mint(2).pow(k) - r) * sum * inv;
      ans *= mint(inv2).pow(k + 1);
      res ^= (unsigned long long)(id) * ans.val();
    }
    fout << res << "\n";
  }
}
