#include <bits/stdc++.h>
using namespace std;
class coordinate {
public:
int x;
int y;
long int z;
coordinate(int a, int b, int c):x(a),y(b),z(c) {};//构析
coordinate() {};
void m_gcd() {
while (gcd(gcd(x,y), z) != 1) {
x=x/gcd(gcd(x,y), z);
y=y/gcd(gcd(x,y), z);
z=z/gcd(gcd(x,y), z);
};//化简用函数
}
};
int main() {
int n;
long int h;
cin >> n >>h;
coordinate point[n];
for (int i = 0; i < n; i++) {
cin >> point[i].x >> point[i].y >> point[i].z;
};//录入数据
for (int i = 0; i < n; i++) {
coordinate temp(point[i].x,point[i].y,2*h-point[i].z);//这是在水面上对应的点
temp.m_gcd();//进行化简
point[i]=temp;//方便输出,现在的point【i】实际上是指向的方向
};
for (int i = 0; i < n; i++) {
cout << point[i].x << " " << point[i].y << " " << point[i].z <<" "<< endl;
};
return 0;
}