#include <iostream>
#include <vector>
#include <cstdint>
#include <utility>
#include <algorithm>

class QueryGenerator {
public:
  QueryGenerator(int N, uint64_t seed) 
    : N(N), state(seed) {}

  inline std::pair<int, int> next_query(int64_t last_answer) {
    state ^= (uint64_t)last_answer + 0x9e3779b97f4a7c15ULL + (state << 6) + (state >> 2);
    auto l = split_mix_64(state) % N;
    auto r = split_mix_64(state) % N;
    return {std::min(l, r), std::max(l, r)};
  }

private:
  uint64_t split_mix_64(uint64_t &x) {
    uint64_t z = (x += 0x9e3779b97f4a7c15ULL);
    z = (z ^ (z >> 30)) * 0xbf58476d1ce4e5b9ULL;
    z = (z ^ (z >> 27)) * 0x94d049bb133111ebULL;
    return z ^ (z >> 31);
  }

  int N;
  uint64_t state;
};

int main() {
  int N, Q;
  std::cin >> N >> Q;
  std::vector<int> start(N);
  std::vector<int> end(N);
  for (int& x : start) {
    std::cin >> x;
  }
  for (int& x : end) {
    std::cin >> x;
  }

  uint64_t state;
  std::cin >> state;
  QueryGenerator query_gen(N, state);
  int64_t last_answer = 0;
  for (int q = 0; q < Q; q++) {
    const auto [l, r] = query_gen.next_query(last_answer);
    // Placeholder for processing the query (l, r)
    last_answer = 0; // Update last_answer based on the query result
    std::cout << last_answer << "\n";
  }
  return 0;
}
