#include <bits/stdc++.h>
using namespace std;
int n, m, k, K[55];
long long a[55], b[55], c[55], f[55][55][111];
int fi[55][55][111], fq[55][55][111];
bool access[55][55][111];
long long ans[55][2];
bool cmp(int a, int b) { return c[a] < c[b]; }
void go(long long q, int i, int j, int x) {
  for (int z = 0; c[K[z]] < c[K[i]]; ++z) {
    if (q > b[K[z]] || q < a[K[z]]) continue;
    if (!access[z][j - 1][q - a[K[z]]]) continue;
    access[i][j][x] = true;
    if (f[z][j - 1][q - a[K[z]]] + a[K[i]] + x > f[i][j][x]) {
      f[i][j][x] = f[z][j - 1][q - a[K[z]]] + a[K[i]] + x;
      fi[i][j][x] = z;
      fq[i][j][x] = q - a[K[z]];
    }
  }
}
int main() {
  scanf("%d%d%d", &n, &m, &k);
  for (int i = 1; i <= m; ++i) {
    scanf("%I64d%I64d%I64d", &a[i], &b[i], &c[i]);
    K[i] = i;
  }
  sort(K + 1, K + m + 1, cmp);
  access[0][0][0] = true;
  for (int i = 0; i <= b[K[1]] - a[K[1]]; ++i) {
    f[1][1][i] = a[K[1]] + i;
    access[1][1][i] = true;
  }
  for (int i = 2; i <= m; ++i) {
    int z = min(i, n);
    for (int j = 1; j <= z; ++j) {
      for (int x = 0; x <= b[K[i]] - a[K[i]]; ++x) {
        if (j == 1) {
          f[i][j][x] = a[K[i]] + x;
          access[i][j][x] = true;
          continue;
        }
        long long q = a[K[i]] + x;
        if (q > k) go(q - k, i, j, x);
        if (q % k == 0) go(q / k, i, j, x);
      }
    }
  }
  long long max = -1;
  int last = 0, kol = 0;
  for (int j = 1; j <= m; ++j) {
    for (int i = 0; i <= b[K[j]] - a[K[j]]; ++i) {
      if (!access[j][n][i]) continue;
      if (f[j][n][i] > max) {
        max = f[j][n][i];
        last = j;
        kol = i;
      }
    }
  }
  if (max == -1)
    printf("NO\n");
  else {
    printf("YES\n");
    for (int i = n; i > 0; --i) {
      ans[i][0] = K[last];
      ans[i][1] = a[K[last]] + kol;
      int z = kol;
      int v = last;
      kol = fq[v][i][z];
      last = fi[v][i][z];
    }
    for (int i = 1; i <= n; ++i) printf("%I64d %I64d\n", ans[i][0], ans[i][1]);
  }
  return 0;
}
