#include <bits/stdc++.h>
using namespace std;
using LL = long long;
const LL IMPOSSIBLE = -1;
const int MAXN = 50;
const int MAXDIFF = 111;
LL dp[MAXN][MAXN][MAXDIFF];
int prv[MAXN][MAXN][MAXDIFF][3];
vector<pair<LL, LL> > a;
vector<pair<int, int> > c;
void printRes(int i, int j, int k) {
  if (i < 0 || j < 0 || k < 0) return;
  printRes(prv[i][j][k][0], prv[i][j][k][1], prv[i][j][k][2]);
  cout << c[i].second + 1 << " " << a[c[i].second].first + k << endl;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  memset(dp, IMPOSSIBLE, sizeof dp);
  memset(prv, IMPOSSIBLE, sizeof prv);
  int n, m, kk;
  cin >> n >> m >> kk;
  a.resize(m);
  c.resize(m);
  for (int i = 0; i < m; ++i) {
    auto& x = a[i];
    auto& y = c[i];
    cin >> x.first >> x.second;
    x.second -= x.first;
    cin >> y.first;
    y.second = i;
  }
  sort(c.begin(), c.end());
  for (int i = 0; i < m; ++i) {
    auto cur = a[c[i].second];
    for (int ad = 0; ad <= cur.second; ++ad) {
      dp[i][0][ad] = ad + cur.first;
    }
    for (int j = 1; j < n; ++j) {
      for (int ad = 0; ad <= cur.second; ++ad) {
        LL cval = cur.first + ad;
        LL t = cval / kk;
        LL tt = cval - kk;
        LL& curDp = dp[i][j][ad];
        int* curPrv = prv[i][j][ad];
        for (int k = 0; k < i && c[k].first < c[i].first; ++k) {
          auto pr = a[c[k].second];
          if (cval % kk == 0 && t >= pr.first && t <= pr.first + pr.second) {
            int it = t - pr.first;
            LL dpVal = dp[k][j - 1][it];
            if (dpVal != IMPOSSIBLE && dpVal + cval > curDp) {
              curDp = dpVal + cval;
              curPrv[0] = k;
              curPrv[1] = j - 1;
              curPrv[2] = it;
            }
          }
          if (tt >= pr.first && tt <= pr.first + pr.second) {
            int it = tt - pr.first;
            LL dpVal = dp[k][j - 1][it];
            if (dpVal != IMPOSSIBLE && dpVal + cval > curDp) {
              curDp = dpVal + cval;
              curPrv[0] = k;
              curPrv[1] = j - 1;
              curPrv[2] = it;
            }
          }
        }
      }
    }
  }
  LL res = -1;
  int ri = 0;
  int rad = 0;
  for (int i = 0; i < m; ++i)
    for (int ad = 0; ad < MAXDIFF; ++ad)
      if (res < dp[i][n - 1][ad]) {
        res = dp[i][n - 1][ad];
        ri = i;
        rad = ad;
      }
  if (res == -1)
    cout << "NO" << endl;
  else {
    cout << "YES" << endl;
    printRes(ri, n - 1, rad);
  }
}
