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:
#include <cassert>// c
#include <ctime>
#include <iostream>// io
#include <iomanip>
#include <fstream>
#include <sstream>
#include <vector>// container
#include <map>
#include <set>
#include <queue>
#include <bitset>
#include <stack>
#include <algorithm>// other
#include <complex>
#include <numeric>
#include <functional>
#include <random>
#include <regex>

using namespace std;
typedef long long ll;

#define ALL(c) (c).begin(),(c).end()
#define FOR(i,l,r) for(int i=(int)l;i<(int)r;++i)
#define REP(i,n) FOR(i,0,n)
#define FORr(i,l,r) for(int i=(int)r-1;i>=(int)l;--i)
#define REPr(i,n) FORr(i,0,n)
#define EACH(i,c) for(__typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define IN(l,v,r) ((l)<=(v) && (v)<(r))
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end())
//debug
#define DUMP(x)  cerr << #x << " = " << (x)
#define LINE()    cerr<< " (L" << __LINE__ << ")"

template<typename T,typename U> T pmod(T x,U M){return (x%M+M)%M;}

typedef long long ll;

//output
template<typename T> ostream& operator << (ostream& os, const vector<T>& as){REP(i,as.size()){if(i!=0)os<<" "; os<<as[i];}return os;}
template<typename T> ostream& operator << (ostream& os, const vector<vector<T>>& as){REP(i,as.size()){if(i!=0)os<<endl; os<<as[i];}return os;}
template<typename T> ostream& operator << (ostream& os, const set<T>& ss){for(auto a:ss){if(a!=ss.begin())os<<" "; os<<a;}return os;}
template<typename T1,typename T2> ostream& operator << (ostream& os, const pair<T1,T2>& p){os<<p.first<<" "<<p.second;return os;}
template<typename K,typename V> ostream& operator << (ostream& os, const map<K,V>& m){bool isF=true;for(auto& p:m){if(!isF)os<<endl;os<<p;isF=false;}return os;}
template<typename T1> ostream& operator << (ostream& os, const tuple<T1>& t){os << get<0>(t);return os;}
template<typename T1,typename T2> ostream& operator << (ostream& os, const tuple<T1,T2>& t){os << get<0>(t)<<" "<<get<1>(t);return os;}
template<typename T1,typename T2,typename T3> ostream& operator << (ostream& os, const tuple<T1,T2,T3>& t){os << get<0>(t)<<" "<<get<1>(t)<<" "<<get<2>(t);return os;}
template<typename T1,typename T2,typename T3,typename T4> ostream& operator << (ostream& os, const tuple<T1,T2,T3,T4>& t){os << get<0>(t)<<" "<<get<1>(t)<<" "<<get<2>(t)<<" "<<get<3>(t);return os;}
template<typename T1,typename T2,typename T3,typename T4,typename T5> ostream& operator << (ostream& os, const tuple<T1,T2,T3,T4,T5>& t){os << get<0>(t)<<" "<<get<1>(t)<<" "<<get<2>(t)<<" "<<get<3>(t)<<" "<<get<4>(t);return os;}
template<typename T1,typename T2,typename T3,typename T4,typename T5,typename T6> ostream& operator << (ostream& os, const tuple<T1,T2,T3,T4,T5,T6>& t){os << get<0>(t)<<" "<<get<1>(t)<<" "<<get<2>(t)<<" "<<get<3>(t)<<" "<<get<4>(t)<<" "<<get<5>(t);return os;}
template<typename T1,typename T2,typename T3,typename T4,typename T5,typename T6,typename T7> ostream& operator << (ostream& os, const tuple<T1,T2,T3,T4,T5,T6,T7>& t){os << get<0>(t)<<" "<<get<1>(t)<<" "<<get<2>(t)<<" "<<get<3>(t)<<" "<<get<4>(t)<<" "<<get<5>(t)<<" "<<get<6>(t);return os;}


// must template
typedef long double D;
const D INF = 1e12,EPS = 1e-8;

typedef tuple<D,D,D> P;

int sig(D a,D b=0){return a<b-EPS?-1:a>b+EPS?1:0;}

bool eq(D a,D b){return sig(a-b)==0;}
bool eq(const P& a,const P& b){
	return sig(get<0>(a)-get<0>(b))==0
	&& sig(get<1>(a)-get<1>(b))==0
	&& sig(get<2>(a)-get<2>(b))==0;
}
bool compX (const P& a,const P& b){
	return !eq(get<0>(a),get<0>(b))?sig(get<0>(a),get<0>(b))<0:
		!eq(get<1>(a),get<1>(b))?sig(get<1>(a),get<1>(b))<0:
		sig(get<2>(a),get<2>(b))<0;
}
namespace std{
	bool operator <  (const P& a,const P& b){return compX(a,b);}
  	bool operator == (const P& a,const P& b){return eq(a,b);}
};


D dist(const P& a,const P& b){
	return sqrt(norm(get<0>(a)-get<0>(b))+norm(get<1>(a)-get<1>(b))+norm(get<2>(a)-get<2>(b)));
}

bool comp(const pair<P,P>& a,const pair<P,P>& b){
	if(sig(dist(a.first,a.second),dist(b.first,b.second))!=0)return dist(a.first,a.second)<dist(b.first,b.second);
	return a<b;
}

namespace std{
	bool operator <  (const pair<P,P>& a,const pair<P,P>& b){return comp(a,b);}
};


// 雑評価
bool compY (const P& a,const P& b){
	return !eq(get<1>(a),get<1>(b))?sig(get<1>(a),get<1>(b))<0:
		!eq(get<2>(a),get<2>(b))?sig(get<2>(a),get<2>(b))<0:
		sig(get<0>(a),get<0>(b))<0;
}
pair<P,P> closestPair(vector<P>& ps,int l,int r){
    if(r-l<2)return make_pair(P(-INF,-INF,-INF),P(INF,INF,INF));
    pair<P,P> res=min(closestPair(ps,l,(l+r)/2),closestPair(ps,(l+r)/2,r));

    vector<P> ips;
    FOR(i,l,r){
    	if(abs(get<0>(ps[i]) - get<0>(ps[(l+r)/2]))<=dist(res.first,res.second))ips.push_back(ps[i]);
    }
    sort(ALL(ips),compY);
    REP(i,ips.size())for(int j=i-10;j<i;j++)if(j>=0)
    	if(make_pair(min(ips[i],ips[j]),max(ips[i],ips[j])) < res){
    		res=make_pair(min(ips[i],ips[j]),max(ips[i],ips[j]));
    	}
    return res;
}
pair<P,P> closestPair(vector<P>& ps){return closestPair(ps,0,ps.size());}

int main() {
	while(true){
		int m,n,S,W;cin >> m >> n >> S >> W;if(m+n==0)break;

		vector<int> xsres(m+n),ysres(m+n),zsres(m+n);
		REP(i,m)cin >> xsres[i] >> ysres[i] >> zsres[i];
		int g = S;
		for(int i=m; i<m+n; i++) {
		  xsres[i] = (g/7)    %100 + 1;
		  ysres[i] = (g/700)  %100 + 1;
		  zsres[i] = (g/70000)%100 + 1;
		  if( g%2 == 0 ) { g = (g/2); }
		  else           { g = (g/2) ^ W; }
		}
		vector<P> ps(n+m);
		//単位ベクトルのみ
		REP(i,n+m){
			D d=sqrt((D)xsres[i]*xsres[i]+(D)ysres[i]*ysres[i]+(D)zsres[i]*zsres[i]);
			ps[i]=make_tuple(xsres[i]/d,ysres[i]/d,zsres[i]/d);
		}
		sort(ALL(ps),compX);
		ps.erase(unique(ALL(ps)),ps.end());
		pair<P,P> res=closestPair(ps);
		int r1=-1,r2=-1;
		P rp1,rp2;
		REP(i,m+n){
			D d=sqrt((D)xsres[i]*xsres[i]+(D)ysres[i]*ysres[i]+(D)zsres[i]*zsres[i]);
			P p=make_tuple(xsres[i]/d,ysres[i]/d,zsres[i]/d);
			if(eq(res.first,p))if(r1==-1 || res.first<rp1)r1=i;
			if(eq(res.second,p))if(r2==-1 || res.second<rp2)r2=i;
		}
		if(make_tuple(xsres[r1],ysres[r1],zsres[r1])> make_tuple(xsres[r2],ysres[r2],zsres[r2]))swap(r1,r2);
		cout << xsres[r1]<<" "<<ysres[r1] << " " <<zsres[r1]<<" ";
		cout << xsres[r2]<<" "<<ysres[r2] << " " <<zsres[r2]<<endl;
	}
}