#include <bits/stdc++.h>
using namespace std;
int n, m, t, d[55][105];
long long f[55][55][105];
struct Task {
  long long l, r;
  int id, c;
  bool operator<(const Task& b) const { return c < b.c; }
} a[55];
void pans(int i, int j, int w) {
  if (j == 1) {
    printf("%d %lld\n", a[i].id, a[i].l + w);
    return;
  }
  for (int k = 1; k < i; ++k)
    if (a[k].c < a[i].c) {
      for (int h = 0; h <= a[k].r - a[k].l; ++h) {
        if (w + a[i].l == h + a[k].l + t &&
            f[i][j][w] == f[k][j - 1][h] + w + a[i].l) {
          pans(k, j - 1, h);
          printf("%d %lld\n", a[i].id, a[i].l + w);
          return;
        }
        if (w + a[i].l == t * (h + a[k].l) &&
            f[i][j][w] == f[k][j - 1][h] + w + a[i].l) {
          pans(k, j - 1, h);
          printf("%d %lld\n", a[i].id, a[i].l + w);
          return;
        }
      }
    } else
      break;
}
int main() {
  scanf("%d%d%d", &n, &m, &t);
  for (int i = 1; i <= m; ++i)
    scanf("%lld%lld%d", &a[i].l, &a[i].r, &a[i].c), a[i].id = i;
  sort(a + 1, a + 1 + m);
  for (int i = 0; i <= a[1].r - a[1].l; ++i) d[1][i] = 1;
  for (int i = 2; i <= m; ++i) {
    for (int j = 0; j <= a[i].r - a[i].l; ++j) d[i][j] = 1;
    for (int k = 1; k < i; ++k)
      if (a[k].c < a[i].c) {
        for (int j = 0; j <= a[k].r - a[k].l; ++j) {
          if (a[k].l + j + t >= a[i].l && a[k].l + j + t <= a[i].r)
            d[i][a[k].l + j + t - a[i].l] =
                max(d[i][a[k].l + j + t - a[i].l], d[k][j] + 1);
          if (t * (a[k].l + j) >= a[i].l && t * (a[k].l + j) <= a[i].r)
            d[i][t * (a[k].l + j) - a[i].l] =
                max(d[i][t * (a[k].l + j) - a[i].l], d[k][j] + 1);
        }
      } else
        break;
  }
  bool flag = false;
  for (int i = 1; i <= m; ++i)
    for (int j = 0; j <= a[i].r - a[i].l; ++j)
      if (d[i][j] >= n) {
        flag = true;
        break;
      }
  if (!flag) {
    printf("NO");
    return 0;
  }
  memset(f, -0x3f, sizeof(f));
  for (int i = 0; i <= a[1].r - a[1].l; ++i) f[1][1][i] = i + a[1].l;
  for (int i = 2; i <= m; ++i) {
    for (int j = 0; j <= a[i].r - a[i].l; ++j) f[i][1][j] = j + a[i].l;
    for (int k = 1; k < i; ++k)
      if (a[k].c < a[i].c) {
        for (int j = 1; j < n; ++j) {
          for (int w = 0; w <= a[k].r - a[k].l; ++w)
            if (f[k][j][w] >= 0) {
              if (a[k].l + w + t >= a[i].l && a[k].l + w + t <= a[i].r)
                f[i][j + 1][a[k].l + w + t - a[i].l] =
                    max(f[i][j + 1][a[k].l + w + t - a[i].l],
                        f[k][j][w] + a[k].l + w + t);
              if (t * (a[k].l + w) >= a[i].l && t * (a[k].l + w) <= a[i].r)
                f[i][j + 1][t * (a[k].l + w) - a[i].l] =
                    max(f[i][j + 1][t * (a[k].l + w) - a[i].l],
                        f[k][j][w] + t * (a[k].l + w));
            }
        }
      } else
        break;
  }
  int ii = -1, ww = -1;
  long long ans = -0x3f3f3f3f;
  for (int i = 1; i <= m; ++i)
    for (int j = 0; j <= a[i].r - a[i].l; ++j)
      if (f[i][n][j] > ans) ii = i, ww = j, ans = f[i][n][j];
  printf("YES\n");
  pans(ii, n, ww);
  return 0;
}
