#include<stdio.h>
#include<vector>
#include<algorithm>
using namespace std;
const int NMAX = 500000,INF = 2e9;
bool vis[NMAX +5];
vector <int> arb[NMAX + 5],bombe[NMAX + 5];
int n,lvl[NMAX + 5],stramos[NMAX + 5][20],cst[NMAX + 5][20];
void dfs (int nod, int tata, int b) {
stramos[0][nod] = tata;
cst[0][nod] = b;
lvl[nod] = lvl[tata] + 1;
vis[nod] = 1;
for(int i = 0; i < arb[nod].size(); i++)
if(!vis[arb[nod][i]])
dfs(arb[nod][i],nod,bombe[nod][i]);
}
int LCA (int x, int y) {
if(x == y)
return x;
int p;
for(p = 0; stramos[p][x] != stramos[p][y]; p++);
if(p)
p--;
return LCA(stramos[p][x],stramos[p][y]);
}
int urca (int x, int niv) {
if(niv == 0)
return x;
int p;
for(p = 0; (1<<p) <= niv; p++);
p--;
return urca(stramos[p][x],niv - (1<<p));
}
int cost (int x, int niv, int res) {
if(niv == 0)
return res;
int p;
for(p = 0; (1<<p) <= niv; p++);
if(p)
p--;
return min(cst[p][x],cost(stramos[p][x], niv - (1<<p), res));
}
int query (int x, int y) {
int resx,resy,lca;
resx = resy = INF;
if(lvl[x] < lvl[y]) {
resy = cost(y, lvl[y] - lvl[x], INF);
y = urca(y, lvl[y] - lvl[x]);
}
if(lvl[y] < lvl[x]) {
resx = cost(x, lvl[x] - lvl[y], INF);
x = urca(x, lvl[x] - lvl[y]);
}
lca = LCA(x,y);
resx = cost(x,lvl[x] - lvl[lca],resx);
resy = cost(y,lvl[y] - lvl[lca],resy);
return min(resx,resy);
}
int main() {
freopen("atac.in","r",stdin);
freopen("atac.out","w",stdout);
int flag,j,nx,ny,nz,x,p,y,z,b,c,d,m,i,a;
scanf("%d%d%d",&n,&m,&p);
for(i = 2; i <= n; i++) {
scanf("%d%d",&a,&b);
arb[i].push_back(a);
arb[a].push_back(i);
bombe[i].push_back(b);
bombe[a].push_back(b);
}
scanf("%d%d%d%d%d%d",&x,&y,&a,&b,&c,&d);
dfs(1,1,0);
cst[0][1] = INF;
for(i = 1; (1<<i) <= n; i++)
for(j = 1; j <= n; j++) {
stramos[i][j] = stramos[i - 1][stramos[i - 1][j]];
if(stramos[i][j])
cst[i][j] = min(cst[i - 1][j], cst[i - 1][stramos[i - 1][j]]);
else
cst[i][j] = INF;
}
z = query(x,y);
for(i = 2; i <= m; i++) {
nx = (x * a + y * b) % n + 1;
ny = (y * c + z * d) % n + 1;
z = query(nx,ny);
if(i >= p)
printf("%d\n",z);
x = nx;
y = ny;
}
return 0;
}