Turing Grandma likes knitting wool sweaters. The -th sweater she knits is represented by a weighted tree . And you are given the pattern weighted tree with vertices numbered from to .
For the current weights of , the sequence of sweaters is defined as follows.
The initial sweater consists of a single vertex.
For , Grandma uses several smaller sweaters of type to knit a larger sweater as follows:
For every , the -th key vertex of is defined to be this single vertex.
For a weighted tree , let be the sum of edge weights on the simple path between vertices and .
For every positive integer , define the complexity of the sweater as
There are queries. Before each query, the generator changes the weight of exactly one edge in . The query is then answered using the current edge weights after this change.
Let be the answer to the -th query. Since the output may be large, you only need to print
Here denotes bitwise xor. The multiplication by the query index is ordinary integer multiplication and is not taken modulo .
Please pay attention to the input format.
The first line contains four integers , , , and , where () is the number of vertices, () is the number of queries, () is the upper bound on query values, and () is the initial seed of the generator.
Each of the next lines contains two integers and for , meaning that there is an edge between and with initial weight , where and .
There is no further input. Edge updates and query values are generated by the following code. The loop is executed for .
unsigned long long x = 123456789, y = 362436069, seed;
unsigned long long gen() {
unsigned long long t;
x ^= x « 16;
x ^= x » 5;
x ^= x « 1;
t = x;
x = y;
y = seed;
seed = t ^ x ^ y;
return seed;
}
for (int i = 1; i <= q; ++i) {
int v = gen() % (n - 1) + 2;
int w = gen() % 100 + 1;
// Change the weight of the edge between v and p\_v to w.
long long k_i = gen() % K + 1;
// Answer the i-th query with value k_i.
}
2 3 2 1
1 1
842