#include <bits/stdc++.h>
#define rep(i,n) ;for (int i=0; i<(n); i++)
// #include <atcoder/all>
#include <random>
using namespace std;
// using namespace atcoder;
using ll = long long;
using P = pair<int, int>;
 
const ll MOD = 1000000007;
const int INF = 1e9; 
// using Graph = vector<vector<int>>;

/*  divisor(n)
    入力：整数 n
    出力：nのすべての約数
    計算量：O(√n)
*/
vector<long long> divisor(long long n) {
    vector<long long> ret;
    for (long long i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            ret.push_back(i);
            if (i * i != n) ret.push_back(n / i);
        }
    }
    sort(ret.begin(), ret.end()); // 昇順に並べる
    return ret;
}

int main(){
  int n;
  cin >> n;
  vector<int> x(n);
  vector<int> y(n);
  vector<pair<int,int>> r(n);
  vector<int> ansa(n);
  vector<int> ansb(n);
  vector<int> ansc(n);
  vector<int> ansd(n);
  vector<int> fansa(n);
  vector<int> fansb(n);
  vector<int> fansc(n);
  vector<int> fansd(n);
  rep(i,n){
    cin >> x[i] >> y[i] >> r[i].first;
    r[i].second = i;
  }
  vector<vector<int>> distx(n, vector<int> (n));
  vector<vector<int>> disty(n, vector<int> (n));
  vector<int> midistu(n,INF);
  vector<int> midistd(n,INF);
  vector<int> midistl(n,INF);
  vector<int> midistr(n,INF);
  rep(i,n){
    rep(j,n){
      distx[i][j] = x[i]-x[j];
      disty[i][j] = y[i]-y[j];
      if(distx[i][j]>0) midistl[i] = min(midistl[i],distx[i][j]);
      else midistr[i] = min(midistr[i],(-1*distx[i][j]));
      if(disty[i][j]>0) midistd[i] = min(midistd[i],disty[i][j]);
      else midistu[i] = min(midistu[i],(-1*disty[i][j]));
    }
  }
  rep(i,n){
  int a = x[i]-midistl[i];
  int b = y[i]-midistd[i];
  int c = x[i]+midistr[i];
  int d = y[i]+midistu[i];
  a = max(0,a);
  b = max(0,b);
  c = min(10000,c);
  d = min(10000,d);
  cout << a << " " << b << " " << c << " " << d << endl;
  }
}
      
#include <string>
#include <vector>
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<stack>
#include<queue>
#include<cmath>
#include<algorithm>
#include<functional>
#include<list>
#include<deque>
#include<bitset>
#include<set>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include<cstring>
#include<sstream>
#include<complex>
#include<iomanip>
#include<numeric>
#include<cassert>
#include<random>
#define X first
#define Y second
#define pb push_back
#define rep(X,Y) for (int (X) = 0;(X) < (int)(Y);++(X))
#define reps(X,S,Y) for (int (X) = (int)(S);(X) < (int)(Y);++(X))
#define rrep(X,Y) for (int (X) = (int)(Y)-1;(X) >=0;--(X))
#define rreps(X,S,Y) for (int (X) = (int)(Y)-1;(X) >= (int)(S);--(X))
#define repe(X,Y) for ((X) = 0;(X) < (Y);++(X))
#define peat(X,Y) for (;(X) < (Y);++(X))
#define all(X) (X).begin(),(X).end()
#define rall(X) (X).rbegin(),(X).rend()
#define eb emplace_back
#define UNIQUE(X) (X).erase(unique(all(X)),(X).end())
#define Endl endl
#define NL <<"\n"
#define cauto const auto

using namespace std;
using ll=long long;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
template<class T> using vv=vector<vector<T>>;
template<class T> inline bool MX(T &l,const T &r){return l<r?l=r,1:0;}
template<class T> inline bool MN(T &l,const T &r){return l>r?l=r,1:0;}
//#undef NUIP
#ifdef NUIP
#include "benri.h"
#else
#define out(args...)
#endif
void ouT(ll x,int d=3){auto re=to_string(x);if((int)re.size()>d) re=x>0?"oo":"-oo";cout<<string(d-re.size(),' ')<<re<<",";}
#ifdef __cpp_init_captures
template<typename T>vector<T> table(int n, T v){ return vector<T>(n, v);}
template <class... Args> auto table(int n, Args... args){auto val = table(args...); return vector<decltype(val)>(n, move(val));}
#endif
template<class A,class B> pair<A,B> operator+(const pair<A,B> &p,const pair<A,B> &q){ return {p.X+q.X,p.Y+q.Y};}
template<class A,class B,class C,class D> pair<A,B>& operator+=(pair<A,B> &p,const pair<C,D> &q){ p.X+=q.X; p.Y+=q.Y; return p;}
template<class A,class B> pair<A,B> operator-(const pair<A,B> &p,const pair<A,B> &q){ return {p.X-q.X,p.Y-q.Y};}
template<class A,class B,class C,class D> pair<A,B>& operator-=(pair<A,B> &p,const pair<C,D> &q){ p.X-=q.X; p.Y-=q.Y; return p;}
template<class A,class B> istream& operator>>(istream &is, pair<A,B> &p){ is>>p.X>>p.Y; return is;}
template<class T=ll> T read(){ T re; cin>>re; return move(re);}
template<class T=ll> T read(const T &dec){ T re; cin>>re; return re-dec;}
template<class T=ll> vector<T> readV(const int sz){ vector<T> re(sz); for(auto &x:re) x=read<T>(); return move(re);}
template<class T=ll> vector<T> readV(const int sz, const T &dec){ vector<T> re(sz); for(auto &x:re) x=read<T>(dec); return move(re);}
vv<int> readG(const int &n,const int &m){ vv<int> g(n); rep(_,m){ cauto a=read<int>(1),b=read<int>(1); g[a].pb(b); g[b].pb(a);} return move(g);}
vv<int> readG(const int &n){ return readG(n,n-1);}
#define TT cauto TTT=read();rep(_,TTT)
const ll MOD=1e9+7; //998244353;

int main(){
  ios_base::sync_with_stdio(false); cin.tie(0);
  cout<<fixed<<setprecision(0);
	auto s=read<string>();
	cauto t=read();
	rep(_,t){
		auto a=s,b=s;
		sort(rall(a));
		sort(all(b));
		s=to_string(stoi(a)-stoi(b));
		out(s,a,b,1);
	}
	cout<<s NL;
  return 0;
}
