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 <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <map>
using namespace std;
const double EPS = 1e-8;
const double INF = 1e18;

bool epsleq(const double &a, const double &b){
    return a +EPS < b;
}
bool epseq(const double &a, const double &b){
    return abs(a-b) < EPS;
}

struct Point{
    double x,y,z;
    Point(double x, double y, double z):x(x), y(y), z(z){}
    Point(){}
    Point &operator +=(const Point &a){ x+=a.x; y+=a.y; z+=a.z; return *this; }
    Point &operator -=(const Point &a){ x-=a.x; y-=a.y; z-=a.z; return *this; }
    Point &operator *=(const double &a){ x*=a; y*=a; z*=a; return *this; }
    Point operator +(const Point &a) const{ return Point(x+a.x, y+a.y, z+a.z); }
    Point operator -(const Point &a) const{ return Point(x-a.x, y-a.y, z-a.z); }
    Point operator *(const double &a) const{ return Point(a*x, a*y, a*z); }
    Point operator -() { return Point(-x, -y, -z); }
    bool operator <(const Point &a) const{
        return !epseq(x, a.x)? x < a.x: !epseq(y, a.y)? y < a.y: epsleq(z, a.z);
    }
    bool operator ==(const Point &a) const{
        double dx=x-a.x, dy=y-a.y, dz=z-a.z;
        return sqrt(dx*dx +dy*dy +dz*dz) < EPS;
    }
};

double dot(const Point &a, const Point &b){
    return a.x*b.x +a.y*b.y +a.z*b.z;
}
Point cross(const Point &a, const Point &b){
    return Point(a.y*b.z -a.z*b.y, a.z*b.x -a.x*b.z, a.x*b.y -a.y*b.x);
}
double abs(const Point &a){
    return sqrt(dot(a, a));
}
Point unit(const Point &a){
    return a *(1/abs(a));
}

bool ycomp(const Point &a, const Point &b){
    return !epseq(a.y, b.y)? a.y < b.y: !epseq(a.x, b.x)? a.x < b.x: epsleq(a.z, b.z);
}
bool dpcomp(const pair<double, pair<Point, Point> > &a, const pair<double, pair<Point, Point> > &b){
    return !epseq(a.first, b.first)? a.first < b.first : a.second < b.second;
}

pair<double, pair<Point, Point> > closest(vector<Point> &v, int first, int last, map<Point, Point> &conv){
    if(last -first <= 1) return make_pair(INF, make_pair(Point(), Point()));
    int mid = (first +last)/2;
    double midx = v[mid].x;
    pair<double, pair<Point, Point> > cp = min(closest(v, first, mid, conv), closest(v, mid, last, conv), dpcomp);
    inplace_merge(v.begin()+first, v.begin()+mid, v.begin()+last, ycomp);
    
    vector<Point> near;
    for(int i=first; i<last; i++){
        if(abs(v[i].x -midx) > cp.first +EPS) continue;
        for(int j=near.size()-1; j>=0; j--){
            if(abs(v[i].y -near[j].y) > cp.first +EPS){
                break;
            }
            pair<double, pair<Point, Point> > ncp(abs(v[i] -near[j]), pair<Point, Point>(conv[v[i]], conv[near[j]]));
            if(ncp.second.second < ncp.second.first) swap(ncp.second.first, ncp.second.second);
            cp = min(cp, ncp, dpcomp);
        }
        near.push_back(v[i]);
    }
    return cp;
}

int main(){
    while(1){
        int m,n,s,w;
        cin >> m >> n >> s >> w;
        if(m==0 && n==0) break;

        vector<Point> v(m+n);
        for(int i=0; i<m; i++){
            cin >> v[i].x >> v[i].y >> v[i].z;
        }
        for(int i=m; i<m+n; i++){
            v[i].x = (s/7) %100 +1;
            v[i].y = (s/700) %100 +1;
            v[i].z = (s/70000) %100 +1;
            if(s%2 == 0){
                s = s/2;
            }else{
                s = (s/2) ^ w;
            }
        }

        n += m;
        map<Point, Point> conv;
        for(int i=0; i<n; i++){
            Point univec = unit(v[i]);
            if(conv.count(univec) == 0){
                conv[univec] = v[i];
            }else{
                conv[univec] = min(conv[univec], v[i]);
            }
        }

        vector<Point> uni;
        for(pair<Point, Point> pp: conv){
            uni.push_back(pp.first);
        }
        pair<double, pair<Point, Point> > ret = closest(uni, 0, uni.size(), conv);
        Point &a = ret.second.first;
        Point &b = ret.second.second;
        cout << fixed << setprecision(0);
        cout << a.x << " " << a.y << " " << a.z << " ";
        cout << b.x << " " << b.y << " " << b.z << endl;
    }
    return 0;
}