#include <cstdio>
#include <algorithm>
#include <vector>
using namespace std;
const long N = 32001;
const long inf = (1ll << 31) - 1;
struct node {
long x, cost;
};
long n, m, p, a [N], cost [N], dp [16][32001], dp2 [16][32001], t [N], nivel [N], p2 = 1, lim, lg2 [32001];
bool used [N];
vector <node> graph [N];
void read () {
long i, g, h;
node temp;
scanf ("%ld%ld%ld", &n, &m, &p);
for (i = 2; i <= n; i ++) {
scanf ("%ld%ld", &g, &h);
temp.x = g;
temp.cost = h;
graph [i].push_back (temp);
temp.x = i;
temp.cost = h;
graph [g].push_back (temp);
}
}
void dfs (long x) {
vector <node> :: iterator it;
used [x] = 1;
for (it = graph [x].begin (); it != graph [x].end (); ++ it)
if (!used [(*it).x] ) {
t [(*it).x] = x;
cost [(*it).x] = (*it).cost;
nivel [(*it).x] = nivel [x] + 1;
dfs ((*it).x);
}
}
long query (long x, long y) {
long ans = inf, i, minim;
if (x == y)
return 0;
if (nivel [x] < nivel [y]) {
lim = lg2 [nivel [y]] + 1;
for (i = lim; i >= 0; i --) {
if (dp [i][y] == 0)
continue;
if (nivel [dp [i][y]] >= nivel [x]) {
ans = min (ans, dp2 [i][y]);
y = dp [i][y];
}
}
}
else
if (nivel [x] > nivel [y]) {
lim = lg2 [nivel [x]] + 1;
for (i = lim; i >= 0; i --) {
if (dp [i][x] == 0)
continue;
if (nivel [dp [i][x]] >= nivel [y]) {
ans = min (ans, dp2 [i][x]);
x = dp [i][x];
}
}
}
if (x == y)
return ans;
minim = nivel [x];
if (nivel [y] < minim)
minim = nivel [y];
lim = lg2 [minim] + 1;
for (i = lim; i >= 0; i --) { // cautare binara
if (dp [i][x] == 0)
continue;
if (dp [i][x] != dp [i][y]) {
ans = min (min (ans, dp2 [i][x]), dp2 [i][y]);
x = dp [i][x];
y = dp [i][y];
}
}
ans = min (ans, dp2 [0][x]);
ans = min (ans, dp2 [0][y]);
return ans;
}
void solve () {
long x, y, a, b, c, d, i, z, nx, ny, j, value;
t [1] = 0;
nivel [1] = 0;
dfs (1);
for (i = 1; i <= n; i ++) {
dp [0][i] = t [i];
dp2 [0][i] = cost [i];
}
lg2 [1] = 0;
for (i = 1; ; i ++) {
p2 = p2 << 1;
lg2 [p2] = i;
if (p2 > n)
break;
lim = i;
for (j = 1; j <= n; j ++) {
dp [i][j] = dp [i - 1][dp [i - 1][j]];
dp2 [i][j] = min (dp2 [i - 1][j], dp2 [i - 1][dp [i - 1][j]]);
}
}
value = 0;
for (i = 1; i <= n; i ++) {
if (lg2 [i])
value = lg2 [i];
else lg2 [i] = value;
}
scanf ("%ld%ld%ld%ld%ld%ld", &x, &y, &a, &b, &c, &d);
for (i = 1; i <= m; i ++) {
z = query (x, y);
nx =(x * a + y * b) % n + 1;
ny =(y * c + z * d) % n + 1;
x = nx;
y = ny;
if (i >= m - p + 1)
printf ("%ld\n", z);
}
}
int main () {
freopen ("atac.in", "r", stdin);
freopen ("atac.out", "w", stdout);
read ();
solve ();
return 0;
}