Problem: 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.



Input

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.


m n S W
x1 y1 z1
x2 y2 z2
:
xm ym zm


The first line contains four integers m, n, S, and W.

The integer m is the number of vectors whose three components are directly specified in the dataset. Starting from the second line, m lines have the three components of m vectors. The i-th line of which indicates the vector vi = (xi, yi, zi). All the vector components are positive integers less than or equal to 100.

The integer n 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 i-th vector vi of the set has three components x[i], y[i], and z[i] generated by this procedure.

Here, values of S and W are the parameters S and W given in the first line of the dataset. You may assume 1 ≤ S ≤ 109 and 1 ≤ W ≤ 109.

The total number of vectors satisfies 2 ≤ m + n ≤ 12 × 104. 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 × 105.

Output

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 va and vb should be formatted in a line as follows.


xa ya za xb yb zb


Two vectors (xa, ya, za) and (xb, yb, zb) are ordered in the dictionary order, that is, va < vb if xa < xb, or if xa = xb and ya < yb, or if xa = xb, ya = yb and za < zb. 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 (vi, vj) is smaller than the pair (vk, vl) if vi < vk, or if vi = vk and vj < vl.

Example

Input

4 0 2013 1124
1 1 1
2 2 2
2 1 1
1 2 1
2 100 131832453 129800231
42 40 46
42 40 46
0 100000 7004674 484521438
0 0 0 0


Output

1 1 1 1 2 1
42 40 46 83 79 91
92 92 79 99 99 85

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
using ld = long double;
#define rep(i, j) for(int i=0; i < (int)(j); i++)
#define all(v) v.begin(),v.end()
const ld EPS = 1e-8;
bool eq(ld a, ld b) { return abs(a - b) < EPS; }

template<class T>
struct Point {
    T x, y, z;
    bool operator < (const Point<T> &r) const { return make_tuple(x, y, z) < make_tuple(r.x, r.y, r.z); }
};

template<class T>
ld length(const Point<T> &p) {
    return sqrtl(p.x * p.x + p.y * p.y + p.z * p.z);
}
template<class T>
ld dot(const Point<T> &a, const Point<T> &b) {
    return a.x * b.x + a.y * b.y + a.z * b.z;
}
template<class T>
ld angle(const Point<T> &a, const Point<T> &b) {
    return acosl(dot(a, b) / length(a) / length(b));
}
template<class T>
Point<ld> unit(Point<T> a) {
    Point<ld> p = {(ld)a.x, (ld)a.y, (ld)a.z};
    ld l = length(p);
    p.x /= l;
    p.y /= l;
    p.z /= l;
    return p;
}

bool solve() {
    using PI = Point<int>;
    int m, n, S, W; cin >> m >> n >> S >> W;
    if(m == 0 and n == 0 and S == 0 and W == 0) return false;
    vector<PI> V(m + n);
    rep(i, m) cin >> V[i].x >> V[i].y >> V[i].z;
    { // generate
        int g = S;
        for(int i=m; i<m+n; i++) {
            V[i].x = (g/7)    %100 + 1;
            V[i].y = (g/700)  %100 + 1;
            V[i].z = (g/70000)%100 + 1;
            if( g%2 == 0 ) { g = (g/2); }
            else           { g = (g/2) ^ W; }
        }
    }
    sort(all(V), [&] (PI a, PI b) { return unit(a).x > unit(b).x; });
    
    ld min_angle = 1e9;    
    PI a, b;

    auto need_check = [&] (PI &a, PI &b) {
        ld alpha = acosl(unit(a).x);
        return cosl(alpha + min_angle) < unit(b).x + EPS;
    };
    
    queue<PI> que;
    rep(i, V.size()) {
        queue<PI> nxt_que;
        while(que.size()) {
            auto p = que.front(); que.pop();
            if(not need_check(p, V[i])) continue;
            ld ang = angle(V[i], p);
            if(ang > EPS) {
                if(min_angle + EPS > ang) {                    
                    auto va = V[i], vb = p;
                    if(vb < va) swap(va, vb);
                    if(!eq(min_angle, ang) or make_pair(a, b) > make_pair(va, vb)) {
                        a = va;
                        b = vb;
                    }
                    min_angle = ang;
                }
            }
            nxt_que.push(p);
        }
        nxt_que.push(V[i]);
        swap(que, nxt_que);
    }
    printf("%d %d %d %d %d %d\n", a.x, a.y, a.z, b.x, b.y, b.z);
    return true;
}

int main() {
    while(solve());
    return 0;
}