#include <iostream>
#include <vector>
#include<algorithm>
#include<string>
#include<math.h>
using namespace std;
const int MAX = 100000;
const int MAX2 = 18;
int lookup[MAX][MAX2];
int arr[MAX];
int loga[MAX];
int query(int L, int R)
{
int j = loga[R - L + 1];
return min(lookup[L][j], lookup[R - (1 << j) + 1][j]);
}
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[i][0] = arr[i];
for (int j = 1; j < MAX2; ++j)
for (int i = 0; i + (1 << j) <= n; ++i)
lookup[i][j] = min(lookup[i][j - 1], lookup[i + (1 << (j - 1))][j - 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+CiNpbmNsdWRlPHN0cmluZz4KI2luY2x1ZGU8bWF0aC5oPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKY29uc3QgaW50IE1BWCA9IDEwMDAwMDsKY29uc3QgaW50IE1BWDIgPSAxODsKCmludCBsb29rdXBbTUFYXVtNQVgyXTsKaW50IGFycltNQVhdOwoKaW50IGxvZ2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