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

#include <iostream>
#include <vector>
#include <unordered_map>
#include <map>
#include <algorithm>

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);
		random_shuffle(lest.begin(), lest.end());
		double d = dist(vd[lest[0]], vd[lest[1]]);
		P3I resA = vt[idxDic[lest[0]]], resB = vt[idxDic[lest[1]]];
		unordered_map<unsigned long long, vector<int>> mp;
		for(int i=0;i<2;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>(1, i)));
			else mp[id].push_back(i);
		}
		for(int i=2;i<lest.size();i++){
			bool update = false;
			const P3D& p = vd[lest[i]];
			unsigned long long baseID = getID(p, 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 = baseID + 101*(101*dx+dy)+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[lest[i]], vd[lest[vi[j]]]);
							if(len < d - 1e-8){
								d = len;
								resA = vt[idxDic[lest[i]]];
								resB = vt[idxDic[lest[vi[j]]]];
								if(resA > resB) swap(resA, resB);
								update = true;
							} else if(len < d + 1e-8){
								P3I tmpA = vt[idxDic[lest[i]]], tmpB = vt[idxDic[lest[vi[j]]]];
								if(tmpA > tmpB) swap(tmpA, tmpB);
								if(make_pair(tmpA, tmpB) < make_pair(resA, resB)){
									resA = tmpA;
									resB = tmpB;
								}
							}
						}
					}
				}
			}
			if(!update){
				const P3D& p = vd[lest[i]];
				unsigned long long id = getID(p, d);
				if(!mp.count(id)) mp.insert(make_pair(id, vector<int>(1, i)));
				else mp[id].push_back(i);
			} else {
				mp.clear();
				for(int j=0;j<=i;j++){
					const P3D& p = vd[lest[j]];
					unsigned long long id = getID(p, d);
					if(!mp.count(id)) mp.insert(make_pair(id, vector<int>(1, j)));
					else mp[id].push_back(j);
				}
			}
		}
		cout << resA.x << " " << resA.y << " " << resA.z << " " << resB.x << " " << resB.y << " " << resB.z << endl;
	}
}

Measured memory_bytes: 19576