//***只要你 目光是瞄准月亮 迷失过 又有何妨***//
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
ll x,y,z;
ll n,h;
ll X,Y,Z;
ll gcd(ll a,ll b)
{
    return b==0?a:gcd(b,a%b);
}
ll gcd3(ll a,ll b,ll c)
{
    return gcd(a,gcd(b,c));
}
void solve()
{
    cin>>n>>h;
    for (int i=1;i<=n;i++)
    {
        cin>>x>>y>>z;
        X=x;
        Y=y;
        Z=2*h-z;
        ll num=gcd3(X,Y,Z);
        X/=num;
        Y/=num;
        Z/=num;
        cout<<X<<" "<<Y<<" "<<Z<<'\n';
    }

}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t;
    t=1;
    while (t--)
    {
        solve();
    }
    return 0;
}