#include <iostream>
#include <vector>
#include<algorithm>
#include<string>
#include<math.h>
using namespace std;
const int MAX = 100000;
const int MAX2 = 18;
int lookup[MAX2][MAX];
int arr[MAX];
int loga[MAX];
int query(int L, int R)
{
int j = loga[R - L + 1];
return min(lookup[j][L], lookup[j][R - (1 << j) + 1]);
}
int main()
{
//freopen("sparse.in", "r", stdin);
//freopen("sparse.out", "w", stdout);
int n, m, a1; scanf("%d%d%d", &n, &m, &a1);
arr[0] = a1;
for (int i = 1; i < n; ++i)
{
int q = (arr[i - 1] * 23 + 21563) % (16714589);
arr[i] = q;
}
loga[0] = -1;
for (int i = 1; i < MAX; ++i)
{
loga[i] = loga[i - 1];
while ((1 << (loga[i] + 1)) <= i) loga[i]++;
}
int q = (int)(log2(n)) + 2;
//!
for (int i = 0; i < n; ++i) lookup[0][i] = arr[i];
for (int i = 1; i < MAX2; ++i)
for (int j = 0; j + (1 << i) <= n; ++j)
lookup[i][j] = min(lookup[i - 1][j], lookup[i - 1][j + (1 << (i - 1))]);
int u1, v1; scanf("%d%d", &u1, &v1);
int answer = query(min(u1 - 1, v1 - 1), max(u1 - 1, v1 - 1));
for (int i = 2; i <= m; ++i)
{
int u = (17 * u1 + 751 + answer + 2 * (i - 1)) % n + 1;
int v = (13 * v1 + 593 + answer + 5 * (i - 1)) % n + 1;
int l = u - 1; int r = v - 1;
if (l > r) swap(l, r);
int newans = query(l, r);
u1 = u;
v1 = v;
answer = newans;
}
printf("%d %d %d", u1, v1, answer);
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8dmVjdG9yPgojaW5jbHVkZTxhbGdvcml0aG0+CiNpbmNsdWRlPHN0cmluZz4KI2luY2x1ZGU8bWF0aC5oPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKY29uc3QgaW50IE1BWCA9IDEwMDAwMDsKY29uc3QgaW50IE1BWDIgPSAxODsKCmludCBsb29rdXBbTUFYMl1bTUFYXTsKaW50IGFycltNQVhdOwoKaW50IGxvZ2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