#include <bits/stdc++.h>
#pragma GCC optimize("O3")
const long long INF = 0x3f3f3f3f3f3f3f3f;
const long long llinf = (1LL << 61);
const int inf = (1 << 30);
const int nmax = 1e2 + 50;
const int mod = 1e9 + 7;
using namespace std;
long long n, m, r, tmp, i, x, y, j, t, k, c[nmax], f[nmax][nmax][nmax],
    pre[nmax][nmax][nmax], val[nmax][nmax][nmax];
long long a[nmax], b[nmax], mx;
vector<pair<long long, long long> > ans;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cerr.tie(0);
  cout.tie(0);
  cin >> n >> m >> r;
  for (i = 1; i <= m; i++) cin >> a[i] >> b[i] >> c[i];
  for (j = 1; j <= m; j++)
    for (i = 0; i <= b[j] - a[j]; i++) f[1][j][i] = a[j] + i;
  for (i = 2; i <= n; i++) {
    for (j = 1; j <= m; j++) {
      for (k = 0; k <= b[j] - a[j]; k++) {
        for (t = 1; t <= m; t++)
          if (c[t] < c[j]) {
            if (a[j] + k - r >= a[t] && a[j] + k - r <= b[t] &&
                f[i - 1][t][a[j] + k - r - a[t]] &&
                f[i][j][k] - a[j] - k < f[i - 1][t][a[j] + k - r - a[t]]) {
              f[i][j][k] = f[i - 1][t][a[j] + k - r - a[t]] + a[j] + k;
              pre[i][j][k] = t;
              val[i][j][k] = a[j] + k - r - a[t];
            }
            if ((a[j] + k) % r == 0 && (a[j] + k) / r >= a[t] &&
                (a[j] + k) / r <= b[t] && f[i - 1][t][(a[j] + k) / r - a[t]] &&
                f[i][j][k] - a[j] - k < f[i - 1][t][(a[j] + k) / r - a[t]]) {
              f[i][j][k] = f[i - 1][t][(a[j] + k) / r - a[t]] + a[j] + k;
              pre[i][j][k] = t;
              val[i][j][k] = (a[j] + k) / r - a[t];
            }
          }
      }
    }
  }
  for (i = 1; i <= m; i++)
    for (j = 0; j <= b[i] - a[i]; j++)
      if (f[n][i][j] > mx) mx = f[n][i][j], x = i, y = j;
  t = n;
  while (f[t][x][y]) {
    ans.push_back({x, a[x] + y});
    tmp = x, x = pre[t][x][y];
    y = val[t][tmp][y];
    t--;
  }
  if (ans.empty()) return cout << "NO" << endl, 0;
  cout << "YES" << endl;
  for (i = n - 1; i >= 0; i--)
    cout << ans[i].first << " " << ans[i].second << endl;
  return 0;
}
