Problem: Vectors have their directions and two vectors make an angle between them. Given a set of three-dimensional vectors, your task is to find the pair among them that makes the smallest angle.



Input

The input is a sequence of datasets. A dataset specifies a set of three-dimensional vectors, some of which are directly given in the dataset and the others are generated by the procedure described below.

Each dataset is formatted as follows.


m n S W
x1 y1 z1
x2 y2 z2
:
xm ym zm


The first line contains four integers m, n, S, and W.

The integer m is the number of vectors whose three components are directly specified in the dataset. Starting from the second line, m lines have the three components of m vectors. The i-th line of which indicates the vector vi = (xi, yi, zi). All the vector components are positive integers less than or equal to 100.

The integer n is the number of vectors generated by the following procedure.


int g = S;
for(int i=m+1; 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 i = m + 1, . . . , m + n, the i-th vector vi of the set has three components x[i], y[i], and z[i] generated by this procedure.

Here, values of S and W are the parameters S and W given in the first line of the dataset. You may assume 1 ≤ S ≤ 109 and 1 ≤ W ≤ 109.

The total number of vectors satisfies 2 ≤ m + n ≤ 12 × 104. Note that exactly the same vector may be specified twice or more in a single dataset.

A line containing four zeros indicates the end of the input. The total of m+n for all the datasets in the input never exceeds 16 × 105.

Output

For each dataset, output the pair of vectors among the specified set with the smallest non-zero angle in between. It is assured that there are at least two vectors having different directions.

Vectors should be indicated by their three components. The output for a pair of vectors va and vb should be formatted in a line as follows.


xa ya za xb yb zb


Two vectors (xa, ya, za) and (xb, yb, zb) are ordered in the dictionary order, that is, va < vb if xa < xb, or if xa = xb and ya < yb, or if xa = xb, ya = yb and za < zb. When a vector pair is output, the smaller vector in this order should be output first.

If more than one pair makes the equal smallest angle, the pair that is the smallest among them in the dictionary order between vector pairs should be output. The pair (vi, vj) is smaller than the pair (vk, vl) if vi < vk, or if vi = vk and vj < vl.

Example

Input

4 0 2013 1124
1 1 1
2 2 2
2 1 1
1 2 1
2 100 131832453 129800231
42 40 46
42 40 46
0 100000 7004674 484521438
0 0 0 0


Output

1 1 1 1 2 1
42 40 46 83 79 91
92 92 79 99 99 85

Solution (in CPP):

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

#include <iostream>
#include <vector>
#include <unordered_map>
#include <map>
#include <algorithm>
#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);
		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>()));
			mp[id].push_back(i);
		}
		for(int i=2;i<lest.size();i++){
			if(i < 2) continue;
			bool update = false;
			{
				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(!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>()));
				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>()));
					mp[id].push_back(j);
				}
			}
		}
		cout << resA.x << " " << resA.y << " " << resA.z << " " << resB.x << " " << resB.y << " " << resB.z << endl;
	}
}