#include <bits/stdc++.h>
using namespace std;
struct Subject {
  unsigned long long a, b;
  int c;
  int i;
  bool operator<(const Subject& w) const { return (*this).c < w.c; }
};
unsigned long long dp[50][50][105];
int who[50][50][105];
int main() {
  int n, m, k;
  cin >> n >> m >> k;
  vector<Subject> v(m);
  for (int i = 0; i < m; i++) {
    cin >> v[i].a >> v[i].b >> v[i].c;
    v[i].i = i + 1;
  }
  sort(v.begin(), v.end());
  memset(who, -1, sizeof(who));
  for (int j = 0; j < m; j++) {
    for (int r = 0; r <= v[j].b - v[j].a; r++) {
      dp[0][j][r] = v[j].a + r;
    }
  }
  for (int i = 1; i < n; i++) {
    for (int j = i; j < m; j++) {
      for (int w = i - 1; w < j; w++) {
        if (v[w].c == v[j].c) break;
        for (int r = 0; r <= v[w].b - v[w].a; r++) {
          if (dp[i - 1][w][r] == 0) continue;
          unsigned long long xx[2] = {(v[w].a + r) + k, (v[w].a + r) * k};
          for (int z = 0; z < 2; z++) {
            auto& x = xx[z];
            if (v[j].a <= x && x <= v[j].b &&
                dp[i][j][x - v[j].a] < dp[i - 1][w][r] + x) {
              dp[i][j][x - v[j].a] = dp[i - 1][w][r] + x;
              who[i][j][x - v[j].a] = w | (z << 10);
            }
          }
        }
      }
    }
  }
  unsigned long long best = 0;
  int start = -1;
  int sr = -1;
  for (int j = n - 1; j < m; j++) {
    for (int r = 0; r <= v[j].b - v[j].a; r++) {
      if (dp[n - 1][j][r] > best) {
        best = dp[n - 1][j][r];
        start = j;
        sr = r;
      }
    }
  }
  if (best == 0) {
    cout << "NO";
  } else {
    cout << "YES\n";
    vector<pair<int, int> > ans(n);
    for (int i = n - 1; i > 0; i--) {
      ans[i] = {start, sr};
      unsigned long long next;
      if ((who[i][start][sr] >> 10) & 1) {
        who[i][start][sr] ^= (1 << 10);
        next = (v[start].a + sr) / k;
      } else {
        next = (v[start].a + sr) - k;
      }
      start = who[i][start][sr];
      sr = next - v[start].a;
    }
    ans[0] = {start, sr};
    for (auto& p : ans) {
      cout << v[p.first].i << " " << v[p.first].a + p.second << "\n";
    }
  }
  return 0;
}
