#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;
}


Measured memory_bytes: 19516