#include <bits/stdc++.h>
using namespace std;
const int N = 104, M = 54;
pair<int, int> pre[N][N][N];
long long f[N][N][N];
struct P {
  long long l, r, c, d, id;
  bool operator<(const P& p) const { return c < p.c; }
} les[N];
int n, m;
long long k;
int main() {
  memset(f, 0xbf, sizeof(f));
  scanf("%d %d %lld", &n, &m, &k);
  for (int i = 1; i <= m; i++) {
    scanf("%lld %lld %lld", &les[i].l, &les[i].r, &les[i].c);
    les[i].id = i;
    les[i].d = les[i].r - les[i].l;
  }
  sort(les + 1, les + m + 1);
  for (int i = 1; i <= m; i++)
    for (int j = 0; j <= les[i].d; j++) f[i][1][j] = les[i].l + j;
  for (int i = 2; i <= m; i++) {
    for (int p = 1; p < i && les[p].c < les[i].c; p++) {
      for (int j = 2; j <= min(i, n); j++) {
        for (int r = 0; r <= les[i].d; r++) {
          long long t = les[i].l + r;
          long long u = t / k;
          if (t % k == 0 && les[p].l <= u && u <= les[p].r) {
            long long d = u - les[p].l;
            long long w = f[p][j - 1][d] + les[i].l + r;
            if (w > f[i][j][r]) {
              f[i][j][r] = w;
              pre[i][j][r] = pair<int, int>(p, d);
            }
          }
          u = les[i].l + r - k;
          if (les[p].l <= u && u <= les[p].r) {
            long long d = u - les[p].l;
            long long w = f[p][j - 1][d] + les[i].l + r;
            if (w > f[i][j][r]) {
              f[i][j][r] = w;
              pre[i][j][r] = pair<int, int>(p, d);
            }
          }
        }
      }
    }
  }
  long long ans = -1;
  int u, v;
  for (int i = 1; i <= m; i++)
    for (int j = 0; j <= les[i].d; j++)
      if (f[i][n][j] > ans) {
        ans = f[i][n][j];
        u = i;
        v = j;
      }
  if (ans == -1)
    puts("NO");
  else {
    vector<P> vec;
    puts("YES");
    for (int j = n, x = u, y = v; j > 0; j--) {
      vec.push_back(P{les[x].id, les[x].l + y, 0, 0});
      int r, s;
      tie(r, s) = pre[x][j][y];
      x = r;
      y = s;
    }
    reverse(vec.begin(), vec.end());
    for (P& p : vec) printf("%lld %lld\n", p.l, p.r);
  }
}
