#include <bits/stdc++.h>
using namespace std;
long long c[55];
struct cmp {
  bool operator()(long long a, long long b) { return c[a] < c[b]; }
};
int main() {
  long long n, m, k;
  long long a[55], b[55], ind[55];
  long long dp[55][55][105][3];
  cin >> n >> m >> k;
  for (long long i = 0; i < m; ++i) {
    cin >> a[i] >> b[i] >> c[i];
    ind[i] = i;
  }
  sort(ind, ind + m, cmp());
  if (0)
    for (long long i = 0; i < m; i++) cout << ind[i] << " ";
  if (0) cout << endl;
  memset(dp, -1, sizeof(dp));
  for (long long i = 0; i < m; i++) {
    for (long long p = 0; p <= (long long)(b[ind[i]] - a[ind[i]]); p++) {
      dp[i][1][p][0] = a[ind[i]] + p;
      dp[i][1][p][1] = i;
      dp[i][1][p][2] = p;
    }
  }
  long long maxVal, maxInd, maxH;
  for (long long i = 1; i < m; i++) {
    for (long long j = 2; j <= min(n, i + 1); j++) {
      for (long long p = 0; p <= (long long)(b[ind[i]] - a[ind[i]]); p++) {
        maxVal = -1;
        maxInd = -1;
        maxH = -1;
        long long cur = a[ind[i]] + p, req1 = cur - k,
                  req2 = ((cur % k) ? -1 : (cur / k));
        for (long long s = i - 1; s >= 0; s--) {
          if (c[ind[s]] == c[ind[i]]) continue;
          if (0)
            cout << "hello " << s << " " << req1 << " " << req2 << " "
                 << a[ind[s]] << " " << b[ind[s]] << " "
                 << dp[s][j - 1][(long long)(req1 - a[ind[s]])][0] << endl;
          if (0) cout << "MAXVAL " << maxVal << endl;
          if (req1 > 0 && req1 <= b[ind[s]] && req1 >= a[ind[s]]) {
            if (dp[s][j - 1][(long long)(req1 - a[ind[s]])][0] > maxVal) {
              maxInd = s;
              maxVal = dp[s][j - 1][(long long)(req1 - a[ind[s]])][0];
              maxH = (req1 - a[ind[s]]);
            }
          }
          if (req2 > 0 && req2 <= b[ind[s]] && req2 >= a[ind[s]]) {
            if (dp[s][j - 1][(long long)(req2 - a[ind[s]])][0] > maxVal) {
              maxInd = s;
              maxVal = dp[s][j - 1][(long long)(req2 - a[ind[s]])][0];
              maxH = (req2 - a[ind[s]]);
            }
          }
        }
        if (0) cout << "FUCK " << maxVal << " " << maxH << endl;
        dp[i][j][p][0] = (maxVal != -1) ? (maxVal + cur) : maxVal;
        dp[i][j][p][1] = maxInd;
        dp[i][j][p][2] = maxH;
        if (0)
          cout << i << " " << j << " " << a[ind[i]] + p << " " << dp[i][j][p][0]
               << endl;
      }
    }
  }
  maxVal = -1;
  maxInd = -1;
  maxH = -1;
  for (long long i = 0; i < m; i++) {
    for (long long j = 0; j <= (b[ind[i]] - a[ind[i]]); j++)
      if (maxVal < dp[i][n][j][0]) {
        maxVal = dp[i][n][j][0];
        maxInd = i;
        maxH = j;
      }
  }
  if (maxVal != -1) {
    long long j = n;
    vector<pair<long long, long long> > v;
    vector<pair<long long, long long> >::iterator it;
    cout << "YES" << endl;
    while (true) {
      if (0) cout << "mind mh " << maxInd << " " << maxH << endl;
      v.push_back(make_pair(ind[maxInd] + 1, a[ind[maxInd]] + maxH));
      long long temp = maxInd;
      maxInd = dp[temp][j][maxH][1];
      maxH = dp[temp][j][maxH][2];
      j--;
      if (j == 0) break;
    }
    for (it = --v.end(), j = n; j > 0; it--, j--) {
      cout << (*it).first << " " << (*it).second << endl;
    }
  } else {
    cout << "NO" << endl;
  }
  return 0;
}
