Vectors have their directions and two vectors make an angle between them.
Given a set of three-dimensional vectors, your task is to find the pair among them that makes the smallest angle.
The input is a sequence of datasets. A dataset specifies a set of three-dimensional vectors, some of which are directly given in the dataset and the others are generated by the procedure described below.
Each dataset is formatted as follows.
x_1 y_1 z_1
x_2 y_2 z_2
x_m y_m z_m
The first line contains four integers , , , and .
The integer is the number of vectors whose three components are directly specified in the dataset. Starting from the second line, lines have the three components of vectors. The -th line of which indicates the vector v_i = (x_i, y_i, z_i). All the vector components are positive integers less than or equal to .
The integer is the number of vectors generated by the following procedure.
int g = S;
for (int i=m+1; i<=m+n; i++) {
x[i] = (g/7) %100 + 1;
y[i] = (g/700) %100 + 1;
z[i] = (g/70000)%100 + 1;
if( g%2 == 0 ) { g = (g/2); }
else { g = (g/2) ^ W; }
}
For i = m+1, , m+n, the -th vector v_i of the set has three components , , and generated by this procedure.
Here, values of and are the parameters and given in the first line of the dataset. You may assume 1 \le S \le 10^9 and 1 \le W \le 10^9.
The total number of vectors satisfies 2 \le m+n \le 12 \times 10^4. Note that exactly the same vector may be specified twice or more in a single dataset.
A line containing four zeros indicates the end of the input. The total of m+n for all the datasets in the input never exceeds 16 \times 10^5.
For each dataset, output the pair of vectors among the specified set with the smallest non-zero angle in between. It is assured that there are at least two vectors having different directions.
Vectors should be indicated by their three components. The output for a pair of vectors v_a and v_b should be formatted in a line as follows.
x_a y_a z_a x_b y_b z_b
Two vectors (x_a, y_a, z_a) and (x_b, y_b, z_b) are ordered in the dictionary order, that is, v_a < v_b if x_a < x_b, or if x_a = x_b and y_a < y_b, or if x_a = x_b, y_a = y_b and z_a < z_b. When a vector pair is output, the smaller vector in this order should be output first.
If more than one pair makes the equal smallest angle, the pair that is the smallest among them in the dictionary order between vector pairs should be output. The pair (v_i, v_j) is smaller than the pair (v_k, v_l) if v_i < v_k, or if v_i = v_k and v_j < v_l.
Example 1