#include <bits/stdc++.h>
using namespace std;
struct Subject {
  long long a, b, c;
  Subject() {}
  Subject(long long a, long long b, long long c) : a(a), b(b), c(c) {}
};
int main() {
  int n, m, k;
  cin >> n >> m >> k;
  vector<Subject> subj(m);
  for (int i = 0; i < m; ++i) {
    cin >> subj[i].a >> subj[i].b >> subj[i].c;
  }
  vector<vector<map<long long, long long> > > mp(
      n, vector<map<long long, long long> >(m));
  vector<vector<map<long long, pair<int, long long> > > > pre(
      n, vector<map<long long, pair<int, long long> > >(m));
  for (int mn = 0; mn < m; ++mn) {
    for (long long i = subj[mn].a; i <= subj[mn].b; ++i) {
      mp[0][mn][i] = i;
    }
  }
  for (int cn = 1; cn < n; ++cn) {
    for (int mn = 0; mn < m; ++mn) {
      for (int pmn = 0; pmn < m; ++pmn) {
        if (subj[pmn].c >= subj[mn].c) {
          continue;
        }
        for (map<long long, long long>::iterator it = mp[cn - 1][pmn].begin();
             it != mp[cn - 1][pmn].end(); ++it) {
          if (it->first * k >= subj[mn].a && it->first * k <= subj[mn].b) {
            if (it->first * k + it->second > mp[cn][mn][it->first * k]) {
              mp[cn][mn][it->first * k] = it->first * k + it->second;
              pre[cn][mn][it->first * k] = (make_pair(pmn, it->first));
            }
          }
          if (it->first + k >= subj[mn].a && it->first + k <= subj[mn].b) {
            if (it->first + k + it->second > mp[cn][mn][it->first + k]) {
              mp[cn][mn][it->first + k] = it->first + k + it->second;
              pre[cn][mn][it->first + k] = (make_pair(pmn, it->first));
            }
          }
        }
      }
    }
  }
  long long mx = 0;
  int mxm = -1;
  long long mxl = -1;
  for (int mn = 0; mn < m; ++mn) {
    for (map<long long, long long>::iterator it = mp[n - 1][mn].begin();
         it != mp[n - 1][mn].end(); ++it) {
      if (mx < it->second) {
        mx = it->second;
        mxl = it->first;
        mxm = mn;
      }
    }
  }
  if (mx != 0) {
    printf("YES\n");
    int m = mxm;
    int gn = n - 1;
    long long l = mxl;
    vector<pair<int, long long> > ans;
    while (gn > 0) {
      ans.push_back(make_pair(m, l));
      int nm = pre[gn][m][l].first;
      long long nl = pre[gn][m][l].second;
      m = nm;
      l = nl;
      --gn;
    }
    ans.push_back(make_pair(m, l));
    for (int i = n - 1; i >= 0; --i) {
      cout << ans[i].first + 1 << " " << ans[i].second << endl;
    }
    return 0;
  }
  printf("NO\n");
  return 0;
}
