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

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

using namespace std;

typedef tuple<double, double, double> P3;

int gcd(int a, int b){ return a%b ? gcd(b, a%b) : b; }
int gcd(int a, int b, int c){ return gcd(a, gcd(b, c)); }
int gcd(const tuple<int, int, int>& t){ return gcd(get<0>(t), get<1>(t), get<2>(t)); }

double dist(const P3& a, const P3& b){
	double x = get<0>(a) - get<0>(b);
	double y = get<1>(a) - get<1>(b);
	double z = get<2>(a) - get<2>(b);
	return sqrt(x*x+y*y+z*z);
}

unsigned long long getID(const P3& p, double d){
	unsigned long long x = get<0>(p)/d;
	unsigned long long y = get<1>(p)/d;
	unsigned long long z = get<2>(p)/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< tuple<int, int, int> > vt(n+m);
		vector< P3 > vd;
		for(int i=0;i<m;i++) cin >> get<0>(vt[i]) >> get<1>(vt[i]) >> get<2>(vt[i]);
		for(int i=m;i<n+m;i++){
			get<0>(vt[i]) = (S/7)    %100+1;
			get<1>(vt[i]) = (S/700)  %100+1;
			get<2>(vt[i]) = (S/70000)%100+1;
			if(S%2 == 0) S = (S/2);
			else         S = (S/2)^W;
		}
		map< tuple<int, int, int>, int > dic;
		for(int i=0;i<n+m;i++){
			int gc = gcd(vt[i]);
			tuple<int, int, int> tp = make_tuple(get<0>(vt[i])/gc, get<1>(vt[i])/gc, get<2>(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]);
			tuple<int, int, int> tp = make_tuple(get<0>(vt[i])/gc, get<1>(vt[i])/gc, get<2>(vt[i])/gc);
			if(dic[tp] != i) continue;
			idxDic.push_back(i);
			double x = get<0>(vt[i]);
			double y = get<1>(vt[i]);
			double z = get<2>(vt[i]);
			double len = sqrt(x*x+y*y+z*z);
			vd.push_back(make_tuple(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 P3& 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 P3& p = vd[lest[i]];
				unsigned long long x = get<0>(p)/d;
				unsigned long long y = get<1>(p)/d;
				unsigned long long z = get<2>(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 = 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;
		tuple<int, int, int> 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 P3& 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 P3& p = vd[i];
				unsigned long long x = get<0>(p)/d;
				unsigned long long y = get<1>(p)/d;
				unsigned long long z = get<2>(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 = 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){
									tuple<int, int, int> 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 << get<0>(resA) << " " << get<1>(resA) << " " << get<2>(resA) << " " << get<0>(resB) << " " << get<1>(resB) << " " << get<2>(resB) << endl;
	}
}

Measured memory_bytes: 20568