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 <vector>
#include <iostream>
#include <map>
#include <algorithm>
#include <random>
#include <complex>
#include <unordered_map>
#include <cmath>
#include <cassert>

using namespace std;
typedef long long ll;
typedef pair<int, int> P;

int gcd(int a, int b) {
    a = abs(a); b = abs(b);
    if (a == 0) return b;
    return gcd(b%a, a);
}

struct K {
    int x, y, z;
    K() {}
    K(int x, int y, int z) : x(x), y(y), z(z) {}
    bool operator== (const K &r) const {
        return (x==r.x && y==r.y && z==r.z);
    }
};

struct T {
    double x, y, z;
    int i;
    T() {}
    T(int x, int y, int z, int i) : x(x), y(y), z(z), i(i) {}
    inline K key(double r) {
        return K(x/r, y/r, z/r);
    }
    double abs() {
        return sqrt(x*x+y*y+z*z);
    }
};

double dist(const T &l, const T &r) {
    double x = l.x-r.x;
    double y = l.y-r.y;
    double z = l.z-r.z;
    return sqrt(x*x + y*y + z*z);
}

const int MN = 100100;
const int MD = 1007;

int n;
int x[MN], y[MN], z[MN];
T p[MN];

auto khash = [](const K &x){
    return x.x^(x.y<<10)^(x.z<<20);
};
unordered_map<K, vector<int>, decltype(khash)> mp(0, khash);

P solve() {
    for (int i = 0; i < n; i++) {
        int g = gcd(gcd(x[i], y[i]), z[i]);
        p[i] = T(x[i]/g, y[i]/g, z[i]/g, i);
    }
    sort(p, p+n, [](const T &l, const T &r) {
        if (l.x != r.x) return l.x < r.x;
        if (l.y != r.y) return l.y < r.y;
        return l.z < r.z;
    });
    n = unique(p, p+n, [](const T &l, const T &r){
        return dist(l, r) < 1e-9;
    })-p;
    shuffle(p, p+n, mt19937());
    for (int i = 0; i < n; i++) {
        double u = p[i].abs();
        p[i].x /= u;
        p[i].y /= u;
        p[i].z /= u;
    }
    double res = dist(p[1], p[0]);
    P resp = P(p[0].i, p[1].i);
    if (resp.first > resp.second) swap(resp.first, resp.second);
    mp.clear();
    mp[p[0].key(res)].push_back(0);
    mp[p[1].key(res)].push_back(1);
    for (int i = 2; i < n; i++) {
        double r = res;
        P rp = resp;
        K k = p[i].key(res);
        bool f = false;
        for (int x = -1; x <= 1; x++) {
            for (int y = -1; y <= 1; y++) {
                for (int z = -1; z <= 1; z++) {
                    auto it = mp.find(K(k.x+x, k.y+y, k.z+z));
                    if (it == mp.end()) continue;
                    for (int t: it->second) {
                        double u = dist(p[i],p[t]);
                        P up = P(p[t].i, p[i].i);
                        if (up.first > up.second) swap(up.first, up.second);
                        if (u < r || (u == r && up < rp)) {
                            f = true;
                            r = u;
                            rp = up;
                        }
                    }
                }
            }
        }
        if (f) {
            res = r;
            resp = rp;
            mp.clear();
            for (int j = 0; j <= i; j++) {
                mp[p[j].key(res)].push_back(j);
            }
        } else {
            mp[p[i].key(res)].push_back(i);
        }
    }
    return resp;
}

typedef tuple<int, int, int> TD;
TD d[MN];
int main() {
    while (true) {
        int m, s, w;
        scanf("%d %d %d %d", &n, &m, &s, &w);
        if (!n && !m) break;
        for (int i = 0; i < n; i++) {
            int x, y, z;
            scanf("%d %d %d", &x, &y, &z);
            d[i] = TD(x,y,z);
        }
        int g = s;
        for (int i = n; i < n+m; i++) {
            int x, y, z;
            x = (g/7) %100+1;
            y = (g/700) % 100+1;
            z = (g/70000) % 100+1;
            d[i] = TD(x,y,z);
            if (g%2 == 0) { g = (g/2); }
            else { g = (g/2) ^ w; }
        }
        n += m;
        sort(d, d+n);
        for (int i = 0; i < n; i++) {
            tie(x[i], y[i], z[i]) = d[i];
        }
        auto r = solve();
        int a = r.first, b = r.second;
        assert(a != b);
        printf("%d %d %d %d %d %d\n", x[a], y[a], z[a], x[b], y[b], z[b]);
    }
    return 0;
}