#include<bits/stdc++.h>
using namespace std;
int gcd(int a,int b){
    if(b==0){
        return a;
    }else{
        return gcd(b,a%b);
    }
}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n,h;
    cin>>n>>h;
    long long x,y,z;
    while(n--){
        cin>>x>>y>>z;
        long long z1=2*h-z;
        long long maxnum=gcd(gcd(x,y),z1);
        cout<<x/maxnum<<" "<<y/maxnum<<" "<<z1/maxnum<<endl;
    }
    return 0;
}