#include <bits/stdc++.h>
typedef struct {
  long long a, b;
  int c;
} t_t;
int n, m, K;
t_t emne[150];
long long dp[51][52][101];
int dp1[51][52][101];
int dp2[51][52][101];
void solve() {
  int i, j, k, l, nextj, nextk;
  long long diff, nextd, cur, next;
  memset(dp, -1, sizeof(dp));
  memset(dp2, -1, sizeof(dp2));
  memset(dp2, -1, sizeof(dp2));
  dp[0][0][0] = 0;
  dp1[0][0][0] = -1;
  dp2[0][0][0] = -1;
  for (i = 0; i < n; i++) {
    for (j = 0; j <= m; j++)
      for (k = 0; k < 101; k++)
        if (dp[i][j][k] > -1) {
          cur = dp[i][j][k];
          if (i == 0 && j == 0) {
            for (nextj = 0; nextj < m; nextj++)
              for (nextk = 0; nextk <= (int)(emne[nextj].b - emne[nextj].a);
                   nextk++) {
                dp[i + 1][nextj + 1][nextk] = nextk + emne[nextj].a;
                dp1[i + 1][nextj + 1][nextk] = k;
                dp2[i + 1][nextj + 1][nextk] = j;
              }
          } else
            for (l = 0; l < m; l++)
              if (emne[l].c > emne[j - 1].c) {
                diff = k + emne[j - 1].a;
                nextd = diff + K;
                next = cur + nextd;
                if (nextd >= emne[l].a && nextd <= emne[l].b &&
                    next > dp[i + 1][l + 1][(int)(nextd - emne[l].a)]) {
                  dp[i + 1][l + 1][(int)(nextd - emne[l].a)] = next;
                  dp1[i + 1][l + 1][(int)(nextd - emne[l].a)] = k;
                  dp2[i + 1][l + 1][(int)(nextd - emne[l].a)] = j;
                }
                nextd = diff * K;
                next = cur + nextd;
                if (nextd >= emne[l].a && nextd <= emne[l].b &&
                    next > dp[i + 1][l + 1][(int)(nextd - emne[l].a)]) {
                  dp[i + 1][l + 1][(int)(nextd - emne[l].a)] = next;
                  dp1[i + 1][l + 1][(int)(nextd - emne[l].a)] = k;
                  dp2[i + 1][l + 1][(int)(nextd - emne[l].a)] = j;
                }
              }
        }
  }
}
int fag[100];
long long ex[100];
void timeplan(int x, int y) {
  int dag = n;
  int i, j;
  while (dag) {
    fag[dag - 1] = x;
    ex[dag - 1] = y + emne[x - 1].a;
    i = dp2[dag][x][y];
    j = dp1[dag][x][y];
    dag--;
    x = i;
    y = j;
  }
  for (i = 0; i < n; i++) printf("%d %I64d\n", fag[i], ex[i]);
}
int main() {
  int i, j;
  long long maks = -1;
  int besti = -1, bestj = 0;
  scanf("%d %d %d", &n, &m, &K);
  for (i = 0; i < m; i++)
    scanf("%I64d %I64d %d", &emne[i].a, &emne[i].b, &emne[i].c);
  solve();
  for (i = 0; i <= m; i++)
    for (j = 0; j <= 100; j++)
      if (dp[n][i][j] > maks) {
        maks = dp[n][i][j];
        besti = i;
        bestj = j;
      }
  if (besti < 0)
    puts("NO");
  else {
    puts("YES");
    timeplan(besti, bestj);
    return 0;
  }
  return 0;
}
