#include <bits/stdc++.h>
using namespace std;
#define R(i, a, b) for (int i = (a); i < (b); ++i)
#define L(i, a, b) for (int i = (b) - 1; i >= (a); --i)
using i64 = long long;
using u64 = unsigned long long;
constexpr int M = 998244353;
struct mint {
  int x;
  const int operator()() {
    return x;
  }
  mint(int _x = 0) : x(_x) {}
};
mint operator+(const mint &a, const mint &b) {
  const int x = a.x + b.x;
  return x < M ? x : x - M;
}
mint operator-(const mint &a, const mint &b) {
  const int x = a.x - b.x;
  return x < 0 ? x + M : x;
}
mint operator*(const mint &a, const mint &b) {
  return i64(a.x) * b.x % M;
}
mint &operator+=(mint &a, const mint &b) {
  a = a + b; return a;
}
mint &operator*=(mint &a, const mint &b) {
  a = a * b; return a;
}
mint pw(mint a, int x = M - 2) {
  mint res = 1;
  for (; x; x >>= 1, a *= a) if (x & 1) res *= a;
  return res;
}
u64 rd(u64 &x) {
  x ^= x << 13; x ^= x >> 7; x ^= x << 17; return x;
}
constexpr int xn = 2000001;
const mint i2 = pw(2);
int n, nQ;
mint rk[xn], a[xn], b[xn];
int main() {
  freopen("noodle.in", "r", stdin); freopen("noodle.out", "w", stdout);
  ios::sync_with_stdio(false); cin.tie(0);
  int test, nT; u64 seed;
  cin >> test >> nT >> seed;
  R(T, 0, nT) {
    int x; i64 k_max; cin >> n >> nQ >> x >> k_max; --x;
    R(i, 0, n) cin >> a[i].x;
    int nk = test <= 2 ? k_max : __builtin_ctz(n) + 5;
    R(k, 0, nk) {
      rk[k] = a[x];
      R(i, 0, n / 2) b[i] = a[i] + a[n - 1 - i];
      R(i, 0, n) a[i] = b[i / 2] * i2;
    }
    i64 r = 0;
    R(i, 0, nQ) {
      i64 k = rd(seed) % k_max;
      r ^= i64(i + 1) * (k >= nk ? rk[nk - 1] : rk[k])();
    }
    cout << r << '\n';
  }
  return 0;
}