# Problem G: Longest Chain

Let us compare two triples `a = (x`_{a}, y_{a}, z_{a}) and `b = (x`_{b}, y_{b}, z_{b}) by a partial order ∠ defined as follows.

`a` ∠ `b` ⇔ `x`_{a} < `x`_{b} and `y`_{a} < `y`_{b} and `z`_{a} < `z`_{b}

Your mission is to find, in the given set of triples, the longest ascending series `a`_{1} ∠ `a`_{2} ∠ ... ∠ `a`_{k}.

## Input

The input is a sequence of datasets, each specifying a set of triples formatted as follows.

`m` `n` `A` `B`
`x`_{1} `y`_{1} `z`_{1}
`x`_{2} `y`_{2} `z`_{2}
...
`x`_{m} `y`_{m} `z`_{m}

Here, `m`, `n`, `A` and `B` in the first line, and all of `x`_{i}, `y`_{i} and `z`_{i} (`i` = 1, . . . , `m`) in the following lines are non-negative integers.

Each dataset specifies a set of `m + n` triples. The triples `p`_{1} through `p`_{m} are explicitly specified in the dataset, the `i`-th triple `p`_{i} being (`x`_{i}, y_{i}, z_{i}). The remaining `n` triples are specified by parameters `A` and `B` given to the following generator routine.

int a = A, b = B, C = ~(1<<31), M = (1<<16)-1;
int r() {
a = 36969 * (a & M) + (a >> 16);
b = 18000 * (b & M) + (b >> 16);
return (C & ((a << 16) + b)) % 1000000;
}

Repeated 3`n` calls of r() defined as above yield values of `x`_{m+1}, `y`_{m+1}, `z`_{m+1}, `x`_{m+2}, `y`_{m+2}, `z`_{m+2}, ..., `x`_{m+n}, `y`_{m+n}, and `z`_{m+n}, in this order.

You can assume that 1 ≤ `m + n` ≤ 3 × 10^{5}, 1 ≤ `A,B` ≤ 2^{16}, and 0 ≤ `x`_{k}, y_{k}, z_{k} < 10^{6} for 1 ≤ `k` ≤ `m + n`.

The input ends with a line containing four zeros. The total of `m + n` for all the datasets does not exceed 2 × 10^{6}.

## Output

For each dataset, output the length of the longest ascending series of triples in the specified set. If `p`_{i1} ∠ `p`_{i2} ∠ ... ∠ `p`_{ik} is the longest, the answer should be `k`.

## Sample Input

6 0 1 1
0 0 0
0 2 2
1 1 1
2 0 2
2 2 0
2 2 2
5 0 1 1
0 0 0
1 1 1
2 2 2
3 3 3
4 4 4
10 0 1 1
3 0 0
2 1 0
2 0 1
1 2 0
1 1 1
1 0 2
0 3 0
0 2 1
0 1 2
0 0 3
0 10 1 1
0 0 0 0

## Output for the Sample Input

3
5
1
3