#include <bits/stdc++.h>
using namespace std;
class subject {
 public:
  long long a, b;
  int c;
  void get() { cin >> a >> b >> c; }
} t[51];
long long d[51][51][101];
int prev_sub[51][51][101], prev_val[51][51][101];
int n, m, k;
bool can_reach(long long a, long long b) { return a * k == b || a + k == b; }
int main() {
  cin >> n >> m >> k;
  for (int i = 0; i < (m); i++) t[i].get();
  memset(d, -1, sizeof(d));
  for (int i = 0; i < (m); i++) {
    int df = t[i].b - t[i].a;
    for (int j = (0); j <= (df); ++j) d[1][i][j] = t[i].a + j;
  }
  for (int dn = (1); dn <= (n - 1); ++dn) {
    for (int i = 0; i < (m); i++) {
      int df = t[i].b - t[i].a;
      for (int j = (0); j <= (df); ++j)
        if (d[dn][i][j] >= 0) {
          long long val = (t[i].a + j) * k;
          for (int l = 0; l < (m); l++)
            if (t[i].c < t[l].c && t[l].a <= val && val <= t[l].b) {
              d[dn + 1][l][val - t[l].a] =
                  max(d[dn][i][j] + val, d[dn + 1][l][val - t[l].a]);
            }
          val = (t[i].a + j) + k;
          for (int l = 0; l < (m); l++)
            if (t[i].c < t[l].c && t[l].a <= val && val <= t[l].b) {
              d[dn + 1][l][val - t[l].a] =
                  max(d[dn][i][j] + val, d[dn + 1][l][val - t[l].a]);
            }
        }
    }
  }
  bool ok = 0;
  int sub = -1, jj = -1;
  long long mx = -1;
  for (int i = 0; i < (m); i++) {
    int df = t[i].b - t[i].a;
    for (int j = (0); j <= (df); ++j)
      if (d[n][i][j] > mx) {
        ok = true;
        mx = d[n][i][j];
        sub = i;
        jj = j;
      }
  }
  if (ok) {
    cout << "YES" << endl;
    vector<pair<int, long long> > v;
    v.push_back(make_pair(sub + 1, t[sub].a + jj));
    for (int dn = (n); dn >= (2); --dn) {
      int psub = -1, pj = -1;
      for (int i = 0; i < (m); i++) {
        int df = t[i].b - t[i].a;
        for (int j = (0); j <= (df); ++j)
          if (d[dn - 1][i][j] + t[sub].a + jj == mx && t[i].c < t[sub].c &&
              can_reach(t[i].a + j, t[sub].a + jj)) {
            psub = i;
            pj = j;
          }
      }
      mx -= t[sub].a + jj;
      sub = psub;
      jj = pj;
      v.push_back(make_pair(sub + 1, t[sub].a + jj));
    }
    reverse((v).begin(), (v).end());
    for (int i = 0; i < (((int)((v).size()))); i++)
      cout << v[i].first << " " << v[i].second << endl;
  } else {
    cout << "NO" << endl;
  }
  return 0;
}
