const readline = require('readline');

const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
});
const tokens: number[][] = [];
rl.on('line', function (line) {
  tokens.push(line.split(' ').map(Number));
}).on('close', function () {
  const [n, h] = tokens.shift();
  for (let i = 0; i < n; ++i) {
    const [x, y, z] = [tokens[i][0], tokens[i][1], 2*h - tokens[i][2]];
    const gcd = getGCD(getGCD(x, y), z);
    const [xi, yj, zk] = [x/gcd, y/gcd, z/gcd];
    console.log(xi + ' ' + yj + ' ' + zk);
  }
});
function getGCD(a: number, b: number): number {
  a = Math.abs(a);
  b = Math.abs(b);
  while (b !== 0) {
    [a, b] = [b, a % b];
  }
  return a;
}