#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:16777216")
using namespace std;
const int N = 50 + 5;
const int M = 100 + 5;
int ttc = 0;
char tt[N * N * M];
int n, m, k;
long long a[N], b[N];
int c[N];
struct T {
  int n, c;
  long long x;
  T() { n = c = x = 0; }
  T(int _n, int _c, long long _x) {
    n = _n;
    c = _c;
    x = _x;
  }
  void *operator new(size_t size) {
    void *res = (void *)(tt + ttc);
    ttc += sizeof(T);
    return res;
  }
};
struct H {
  size_t operator()(const T &t) const { return t.n * 13 + t.c * 17 + t.x * 37; }
};
struct C {
  bool operator()(const T &a, const T &b) const {
    return a.n == b.n && a.c == b.c && a.x == b.x;
  }
};
unordered_map<T, bool, H, C> vs;
unordered_map<T, long long, H, C> dp;
unordered_map<T, int, H, C> pr1;
unordered_map<T, long long, H, C> pr2;
long long D(T t) {
  if (t.n == n) return 0;
  bool &vis = vs[t];
  long long &res = dp[t];
  int &pre1 = pr1[t];
  long long &pre2 = pr2[t];
  if (vis) return res;
  vis = 1;
  res = -1;
  for (int i = 0; i < (int)(m); i++)
    if (c[i] > t.c)
      if (!t.n) {
        for (long long x = a[i]; x <= b[i]; x++) {
          T f(t.n + 1, c[i], x);
          long long cur = D(f);
          if (cur != -1) {
            cur += x;
            if (cur > res) {
              res = cur;
              pre1 = i;
              pre2 = x;
            }
          }
        }
      } else {
        if (a[i] <= t.x + k && t.x + k <= b[i]) {
          T f(t.n + 1, c[i], t.x + k);
          long long cur = D(f);
          if (cur != -1) {
            cur += t.x + k;
            if (cur > res) {
              res = cur;
              pre1 = i;
              pre2 = t.x + k;
            }
          }
        }
        if (a[i] <= t.x * k && t.x * k <= b[i]) {
          T f(t.n + 1, c[i], t.x * k);
          long long cur = D(f);
          if (cur != -1) {
            cur += t.x * k;
            if (cur > res) {
              res = cur;
              pre1 = i;
              pre2 = t.x * k;
            }
          }
        }
      }
  return res;
}
int main() {
  scanf("%d %d %d", &n, &m, &k);
  for (int i = 0; i < (int)(m); i++)
    scanf("%I64d %I64d %d", &a[i], &b[i], &c[i]);
  T t(0, 0, 0);
  long long x = D(t);
  if (x != -1) {
    printf("YES\n");
    while (t.n < n) {
      printf("%d %I64d\n", pr1[t] + 1, pr2[t]);
      t = T(t.n + 1, c[pr1[t]], pr2[t]);
    }
  } else
    printf("NO\n");
  return 0;
}
