// ACM-ICPCアジア地区予選2013 F. Directional Resemblance

#include <iostream>
#include <vector>
#include <unordered_map>
#include <map>
#include <cmath>
#include <cstdlib>

using namespace std;

class P3D {
public:
	P3D(double x = 0, double y = 0, double z = 0) : x(x), y(y), z(z) {}
	double x, y, z;
};

class P3I {
public:
	P3I(int x = 0, int y = 0, int z = 0) : x(x), y(y), z(z) {}
	int x, y, z;
	bool operator < (const P3I& p) const { return x < p.x || (x == p.x && (y < p.y || (y == p.y && z < p.z))); }
	bool operator == (const P3I& p) const { return x == p.x && y == p.y && z == p.z; }
	bool operator > (const P3I& p) const { return x > p.x || (x == p.x && (y > p.y || (y == p.y && z > p.z))); }
	P3I operator / (int g) const { return P3I(x/g, y/g, z/g); }
};

inline int gcd(int a, int b){ return a%b ? gcd(b, a%b) : b; }
inline int gcd(int a, int b, int c){ return gcd(a, gcd(b, c)); }
inline int gcd(const P3I& t){ return gcd(t.x, t.y, t.z); }

double dist(const P3D& a, const P3D& b){
	double x = a.x - b.x;
	double y = a.y - b.y;
	double z = a.z - b.z;
	return sqrt(x*x+y*y+z*z);
}

unsigned long long getID(const P3D& p, double d){
	unsigned long long x = p.x/d;
	unsigned long long y = p.y/d;
	unsigned long long z = p.z/d;
	return 101*(101*x+y)+z;
}

int main(){
	srand(1000000007);
	int m, n, S, W;
	while(cin >> m >> n >> S >> W && (n||m)){
		vector< P3I > vt(n+m);
		vector< P3D > vd;
		for(int i=0;i<m;i++) cin >> vt[i].x >> vt[i].y >> vt[i].z;
		for(int i=m;i<n+m;i++){
			vt[i].x = (S/7)    %100+1;
			vt[i].y = (S/700)  %100+1;
			vt[i].z = (S/70000)%100+1;
			if(S%2 == 0) S = (S/2);
			else         S = (S/2)^W;
		}
		map< P3I, int > dic;
		for(int i=0;i<n+m;i++){
			int gc = gcd(vt[i]);
			P3I tp = vt[i]/gc;
			if(dic.count(tp)){
				if(vt[dic[tp]] > vt[i]) dic[tp] = i;
			} else {
				dic[tp] = i;
			}
		}
		vector<int> idxDic;
		for(int i=0;i<m+n;i++){
			int gc = gcd(vt[i]);
			P3I tp = vt[i]/gc;
			if(dic[tp] != i) continue;
			idxDic.push_back(i);
			double x = vt[i].x;
			double y = vt[i].y;
			double z = vt[i].z;
			double len = sqrt(x*x+y*y+z*z);
			vd.push_back(P3D(x/len, y/len, z/len));
		}
		vector<int> lest;
		for(int i=0;i<vd.size();i++) lest.push_back(i);
		double d = 1e12;
		while(true){
			vector<int> next;
			vector<int> valid(lest.size(), 0);
			d = 1e12;
			int target = rand()%lest.size();
			for(int i=0;i<lest.size();i++){
				if(i == target) continue;
				d = min(d, dist(vd[lest[i]], vd[lest[target]]));
			}
			d /= 12.0;
			unordered_map<unsigned long long, vector<int>> mp;
			for(int i=0;i<lest.size();i++){
				const P3D& p = vd[lest[i]];
				unsigned long long id = getID(p, d);
				if(!mp.count(id)) mp.insert(make_pair(id, vector<int>()));
				mp[id].push_back(i);
			}
			for(int i=0;i<lest.size();i++){
				const P3D& p = vd[lest[i]];
				unsigned long long x = p.x/d;
				unsigned long long y = p.y/d;
				unsigned long long z = p.z/d;
				for(int dx=-1;dx<=1;dx++){
					for(int dy=-1;dy<=1;dy++){
						for(int dz=-1;dz<=1;dz++){
							unsigned long long id = 101*(101*(x+dx)+(y+dy))+z+dz;
							if(dx==0 && dy==0 && dz==0){
								if(mp[id].size() > 1){
									valid[i] = 1;
								}
							} else {
								if(mp.count(id)){
									valid[i] = 1;
								}
							}
						}
					}
				}
			}
			for(int i=0;i<valid.size();i++){
				if(valid[i]) next.push_back(lest[i]);
			}
			if(next.empty()) break;
			lest = next;
		}
		d *= 12.0;
		double minDist = 1e12;
		P3I resA = vt[0], resB = vt[1];
		if(resA > resB) swap(resA, resB);
		int cnt = 0;
		{
			unordered_map<unsigned long long, vector<int>> mp;
			for(int i=0;i<vd.size();i++){
				const P3D& p = vd[i];
				unsigned long long id = getID(p, d);
				if(!mp.count(id)) mp.insert(make_pair(id, vector<int>()));
				mp[id].push_back(i);
			}
			for(int i=0;i<vd.size();i++){
				const P3D& p = vd[i];
				unsigned long long x = p.x/d;
				unsigned long long y = p.y/d;
				unsigned long long z = p.z/d;
				for(int dx=-1;dx<=1;dx++){
					for(int dy=-1;dy<=1;dy++){
						for(int dz=-1;dz<=1;dz++){
							unsigned long long id = 101*(101*(x+dx)+(y+dy))+z+dz;
							if(!mp.count(id)) continue;
							const vector<int>& vi = mp[id];
							for(int j=0;j<vi.size();j++){
								if(i == vi[j]) continue;
								double len = dist(vd[i], vd[vi[j]]);
								if(len < minDist - 1e-8){
									minDist = len;
									resA = vt[idxDic[i]];
									resB = vt[idxDic[vi[j]]];
									if(resA > resB) swap(resA, resB);
								} else if(len < minDist + 1e-8){
									P3I tmpA = vt[idxDic[i]], tmpB = vt[idxDic[vi[j]]];
									if(tmpA > tmpB) swap(tmpA, tmpB);
									if(make_pair(tmpA, tmpB) < make_pair(resA, resB)){
										resA = tmpA;
										resB = tmpB;
									}
								}
							}
						}
					}
				}
			}
		}
		cout << resA.x << " " << resA.y << " " << resA.z << " " << resB.x << " " << resB.y << " " << resB.z << endl;
	}
}

Measured memory_bytes: 19960