#include <bits/stdc++.h>
using namespace std;
const int N_MAX = 52, D_MAX = 102;
struct Subj {
  long long a, b;
  int c, id, d;
  bool operator<(const Subj& s) const { return c < s.c; }
};
long long f[N_MAX][N_MAX][D_MAX];
int prv_subj[N_MAX][N_MAX][D_MAX];
int prv_ex[N_MAX][N_MAX][D_MAX];
int main() {
  int n, m, k0;
  cin >> n >> m >> k0;
  vector<Subj> v;
  for (int i = 0; i < m; ++i) {
    Subj s;
    cin >> s.a >> s.b >> s.c;
    s.d = s.b - s.a;
    s.id = i;
    v.push_back(s);
  }
  for (int i = 0; i < m; ++i) {
    const Subj& s = v[i];
    for (int j = 0; j <= s.d; ++j) f[0][i][j] = s.a + j;
  }
  for (int i = 1; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      long long ga = v[j].a, gb = v[j].b;
      for (int k = 0; k < m; ++k) {
        if (v[k].c >= v[j].c) continue;
        long long a = v[k].a;
        for (int l = 0; l <= v[k].d; ++l) {
          long long nex[2];
          nex[0] = a + l + k0;
          nex[1] = (a + l) * k0;
          for (int z = 0; z < 2; ++z) {
            long long nv = nex[z];
            if (nv >= ga && nv <= gb) {
              int sh = nv - ga;
              if (f[i - 1][k][l] != 0 && f[i - 1][k][l] + nv > f[i][j][sh]) {
                f[i][j][sh] = f[i - 1][k][l] + nv;
                prv_ex[i][j][sh] = l;
                prv_subj[i][j][sh] = k;
              }
            }
          }
        }
      }
    }
  }
  long long ans = -1;
  int ans_subj = -1, ans_ex = -1;
  for (int i = 0; i < m; ++i)
    for (int j = 0; j <= v[i].d; ++j) {
      if (f[n - 1][i][j] > ans) {
        ans = f[n - 1][i][j];
        ans_subj = i;
        ans_ex = j;
      }
    }
  if (ans <= 0) {
    cout << "NO\n";
    return 0;
  } else {
    cout << "YES\n";
    vector<pair<int, long long> > w;
    for (int i = n - 1; i >= 0; --i) {
      w.push_back(make_pair(ans_subj, ans_ex + v[ans_subj].a));
      int n_ans_subj = prv_subj[i][ans_subj][ans_ex];
      int n_ans_ex = prv_ex[i][ans_subj][ans_ex];
      ans_subj = n_ans_subj, ans_ex = n_ans_ex;
    }
    reverse(w.begin(), w.end());
    for (int i = 0; i < n; ++i) {
      cout << w[i].first + 1 << ' ' << w[i].second << '\n';
    }
  }
  return 0;
}
