#include <bits/stdc++.h>
using namespace std;
const int MN = 110;
long long d[MN / 2][MN / 2][MN];
bool mark[MN / 2][MN / 2][MN];
long long d2[MN / 2][MN / 2][MN];
long long p[MN / 2][MN / 2][MN];
long long lm[MN][3], n, m, k;
long long inf = 1000000000;
long long memz(long long nd, long long ns, long long ts) {
  if (mark[nd][ns][ts]) {
    return d[nd][ns][ts];
  } else {
    if (nd == n - 1) {
      return lm[ns][0] + ts;
    }
    mark[nd][ns][ts] = 1;
    long long Max = -inf;
    long long pr = -1;
    long long TS = -1;
    ;
    long long l = lm[ns][0];
    for (long long i = 0; i < m; i++) {
      if (lm[i][2] > lm[ns][2]) {
        long long nts = l + ts + k;
        if (lm[i][0] <= nts && nts <= lm[i][1]) {
          if (Max < memz(nd + 1, i, nts - lm[i][0])) {
            Max = memz(nd + 1, i, nts - lm[i][0]);
            pr = i;
            TS = nts - lm[i][0];
          }
        }
        nts = (l + ts) * k;
        if (lm[i][0] <= nts && nts <= lm[i][1]) {
          if (Max < memz(nd + 1, i, nts - lm[i][0])) {
            Max = memz(nd + 1, i, nts - lm[i][0]);
            pr = i;
            TS = nts - lm[i][0];
          }
        }
      }
    }
    Max += ts + l;
    p[nd][ns][ts] = pr;
    d[nd][ns][ts] = Max;
    d2[nd][ns][ts] = TS;
    return Max;
  }
}
long long memz2(long long nd, long long ns, long long ts) {
  cout << ns + 1 << " " << lm[ns][0] + ts << endl;
  if (nd == n - 1) {
    return 0;
  }
  memz2(nd + 1, p[nd][ns][ts], d2[nd][ns][ts]);
}
int main() {
  inf *= 1000000000;
  cin >> n >> m >> k;
  for (long long i = 0; i < m; i++) {
    long long a, b, c;
    cin >> a >> b >> c;
    lm[i][0] = a;
    lm[i][1] = b;
    lm[i][2] = c;
  }
  long long Max = 0;
  long long p, TS;
  for (long long i = 0; i < m; i++) {
    long long d = lm[i][1] - lm[i][0];
    for (long long ts = 0; ts <= d; ts++) {
      if (memz(0, i, ts) > Max) {
        Max = memz(0, i, ts);
        p = i;
        TS = ts;
      }
    }
  }
  if (Max == 0) {
    cout << "NO" << endl;
  } else {
    cout << "YES" << endl;
    memz2(0, p, TS);
  }
}
