#include <bits/stdc++.h>
using namespace std;
const long long INF = 0x3f3f3f3f;
void Open() {}
long long n, m, k;
long long dp[55][55][55][110];
struct info {
  long long a, b, c, id;
  bool operator<(const info& o) const { return c < o.c; }
} sub[110];
int paidx[110][110][110][3];
long long pat[110][110];
long long ansidx[110];
long long anst[110];
int main() {
  Open();
  memset(paidx, -1, sizeof paidx);
  scanf("%I64d%I64d%I64d", &n, &m, &k);
  for (long long i = 0; i < m; i++)
    scanf("%I64d%I64d%I64d", &sub[(i)].a, &sub[(i)].b, &sub[(i)].c),
        sub[(i)].b -= sub[(i)].a, sub[(i)].id = i;
  sort(sub, sub + m);
  for (long long i = 0; i <= sub[(0)].b; i++) dp[0][1][0][i] = i + sub[(0)].a;
  for (long long i = 1; i < m; i++)
    for (long long j = 1; j <= min(i + 1, n); j++) {
      for (long long s = j - 1; s < i; s++)
        for (long long t = 0; t <= sub[(s)].b; t++)
          dp[i][j][s][t] = dp[i - 1][j][s][t];
      if (j == 1) {
        for (long long t = 0; t <= sub[(i)].b; t++)
          dp[i][j][i][t] = t + sub[(i)].a;
        continue;
      }
      for (long long t = 0; t <= sub[(i)].b; t++)
        for (long long s = j - 2; s < i; s++) {
          if (sub[(s)].c >= sub[(i)].c) continue;
          if (sub[(i)].a + t - sub[(s)].a - k >= 0 &&
              sub[(i)].a + t - sub[(s)].a - k <= sub[(s)].b &&
              dp[i][j][i][t] <
                  dp[i - 1][j - 1][s][sub[(i)].a + t - sub[(s)].a - k] +
                      sub[(i)].a + t &&
              dp[i - 1][j - 1][s][sub[(i)].a + t - sub[(s)].a - k] != 0) {
            dp[i][j][i][t] =
                dp[i - 1][j - 1][s][sub[(i)].a + t - sub[(s)].a - k] +
                sub[(i)].a + t;
            paidx[i][j][t][0] = j - 1;
            paidx[i][j][t][1] = s;
            paidx[i][j][t][2] = sub[(i)].a + t - sub[(s)].a - k;
          }
          if ((sub[(i)].a + t) % k == 0 &&
              (sub[(i)].a + t) / k - sub[(s)].a >= 0 &&
              (sub[(i)].a + t) / k - sub[(s)].a <= sub[(s)].b &&
              dp[i][j][i][t] <
                  dp[i - 1][j - 1][s][(sub[(i)].a + t) / k - sub[(s)].a] +
                      sub[(i)].a + t &&
              dp[i - 1][j - 1][s][(sub[(i)].a + t) / k - sub[(s)].a] != 0) {
            dp[i][j][i][t] =
                dp[i - 1][j - 1][s][(sub[(i)].a + t) / k - sub[(s)].a] +
                sub[(i)].a + t;
            paidx[i][j][t][0] = j - 1;
            paidx[i][j][t][1] = s;
            paidx[i][j][t][2] = (sub[(i)].a + t) / k - sub[(s)].a;
          }
        }
    }
  long long ans = 0;
  long long tmp = n, preidx, preans;
  pair<long long, long long> pre;
  for (long long i = 0; i < m; i++)
    for (long long j = 0; j <= sub[(i)].b; j++)
      if (ans < dp[m - 1][n][i][j])
        ans = dp[m - 1][n][i][j], pre = pair<long long, long long>(i, j),
        preidx = n, preans = j + sub[(i)].a;
  if (ans == 0) {
    cout << "NO" << endl;
    return 0;
  }
  cout << "YES" << endl;
  while (pre != pair<long long, long long>(-1, -1)) {
    ansidx[--tmp] = pre.first;
    anst[tmp] = pre.second + sub[(pre.first)].a;
    pair<long long, long long> pretmp = pre;
    int tmppreidx = preidx;
    preidx = paidx[pretmp.first][tmppreidx][pretmp.second][0];
    pre.first = paidx[pretmp.first][tmppreidx][pretmp.second][1];
    pre.second = paidx[pretmp.first][tmppreidx][pretmp.second][2];
  }
  for (long long i = 0; i < n; i++)
    printf("%I64d %I64d\n", sub[(ansidx[i])].id + 1, anst[i]);
  return 0;
}
