#include <bits/stdc++.h>
using namespace std;

namespace ClosestPair{
	// DIM=3????£????????¬????????????????????????´?????????getNearPoints()makeBucket()?????´
	const double EPS = 1e-9;
	const int DIM = 3;
	typedef array<double,DIM> P;

	double dist(const P &p1,const P &p2){
		double ans = 0;
		for(int i = 0 ; i < DIM ; i++)
			ans += (p1[i]-p2[i])*(p1[i]-p2[i]);
		return sqrt(ans);
	}
	typedef array<int,DIM> Block;
	typedef map<Block,vector<int>> Bucket;
	Block getBlock(const P &p,double w){
		Block res;
		for(int i = 0 ; i < DIM ; i++) res[i] = p[i] / w;
		return res;
	}
	vector<int> getNearPoints(const Bucket &b,double w,const P &p){
		vector<int> res;
		auto key = getBlock(p,w);
		for(int x0 = -1 ; x0 <= 1 ; x0++)
			for(int x1 = -1 ; x1 <= 1 ; x1++)
				for(int x2 = -1 ; x2 <= 1 ; x2++){
					auto it = b.find(Block{key[0]+x0,key[1]+x1,key[2]+x2});
					if( it != b.end() ){
						for( int id : it->second ) res.push_back(id);
					}
				}
		return res;
	}
	//???w???n?¬?????????±????????????????????????????????¨????????°??¨??????????????????????±????????????¨?????§?????????
	Bucket makeBucket(const vector<P> &ps,double w){
		Bucket b;
		for(int i = 0 ; i < ps.size() ; i++)
			b[getBlock(ps[i],w)].push_back(i);
		return b;
	}
	// ????????????????????¢????????????????????±???????¬??§??????? map????????¨?????????????????§???????¨???????O(n log n)
	// ?????±??????????????????????§???????????????????????¢????????£?????????????????????????????????§??????????????§???????????????2w??????????????????????????????w???????????????????\??????????
	double closetPairDistance(vector<P> ps){
		assert(ps.size()>=2);
		random_shuffle(ps.begin(),ps.end());
		double w = dist(ps[0],ps[1]);
		vector<P> build = {ps[0],ps[1]};
		auto b = makeBucket(build,2*w);
		for(int i = 2 ; i < ps.size() ; i++){
			double next_w = w;
			for( int j : getNearPoints(b,2*w,ps[i]) )
				next_w = min(next_w,dist(ps[i],ps[j]));
			build.push_back(ps[i]);
			if( w - EPS > next_w ){
				w = next_w;
				b = makeBucket(build,2*w);
			}else{
				b[getBlock(ps[i],2*w)].push_back(i);
			}
		}
		return w;
	}
};

using namespace ClosestPair;


struct Pt{
	double x,y,z;
};
bool operator < (const Pt &a,const Pt &b){
	if( fabs(a.x-b.x) > EPS ) return a.x < b.x;
	if( fabs(a.y-b.y) > EPS ) return a.y < b.y;
	if( fabs(a.z-b.z) > EPS ) return a.z < b.z;
	return false;
}

double X[150000];
double Y[150000];
double Z[150000];

int main(){
	int m,n,S,W;
	int tst = 1;
	while( cin >> m >> n >> S >> W && m+n ){
		map<Pt,vector<P>> dic;
		for(int i = 0 ; i < m ; i++){
			scanf("%lf%lf%lf",X+i,Y+i,Z+i);
		}
		int g = S;
		for(int i=m; 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(int i = 0 ; i < m+n ; i++){
			double x = X[i];
			double y = Y[i];
			double z = Z[i];
			P p = {x,y,z};
			double d = dist(P{0,0,0},p);
			Pt e;
			e.x = x / d;
			e.y = y / d;
			e.z = z / d;
			dic[e].push_back(p);
		}
		vector<P> ps;
		vector<P> cand;
		for( auto &p : dic ){
			ps.push_back(P{p.first.x,p.first.y,p.first.z});
			
			cand.push_back(*min_element(p.second.begin(),p.second.end()));
		}
	
		double w = closetPairDistance(ps);
		auto b = makeBucket(ps,2*w);
		pair<P,P> best = {P{1e9,1e9,1e9},P{1e9,1e9,1e9}};
		for(int i = 0 ; i < ps.size() ; i++){
			for( auto j : getNearPoints(b,2*w,ps[i]) ){
				if( i != j ){
					if( fabs(dist(ps[i],ps[j])-w) < EPS ){
						best = min(best,pair<P,P>{cand[i],cand[j]});
					}
				}
			}
		}
		cout << (int)best.first[0] << " " << (int)best.first[1] << " " << (int)best.first[2] << " ";
		cout << (int)best.second[0] << " " << (int)best.second[1] << " " << (int)best.second[2] << "\n";
		
	}
	

}

Measured memory_bytes: 44408