#include <bits/stdc++.h>
using namespace std;
struct NODE {
  long long a, b;
  int c, ind;
};
const int N = 110, K = 60;
NODE a[N];
long long d[K][K][N];
pair<int, int> par[K][K][N];
bool comp(NODE x, NODE y) { return (x.c < y.c); }
void pp(int i, int j, long long k) {
  if (!i) return;
  pair<int, int> u = par[i][j][k];
  pp(i - 1, u.first, u.second);
  cout << a[j].ind + 1 << " " << k + a[j].a << endl;
  return;
}
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int n, m;
  long long k;
  cin >> n >> m >> k;
  for (int i = 0; i < m; i++) {
    cin >> a[i].a >> a[i].b >> a[i].c;
    a[i].ind = i;
  }
  sort(a, a + m, comp);
  for (int i = 0; i < m; i++)
    for (int j = 0; j <= a[i].b - a[i].a; j++) {
      d[1][i][j] = j + a[i].a;
      par[1][i][j] = {0, 0};
    }
  for (int i = 2; i <= n; i++)
    for (int j = i - 1; j < m; j++)
      for (int t = 0; t <= a[j].b - a[j].a; t++) {
        d[i][j][t] = -1;
        for (int l = j - 1; l >= 0 && l + 2 >= i; l--) {
          long long tmp = t + a[j].a, w1 = tmp - k, w2 = tmp / k;
          for (int z = 0; z < 2; z++) {
            long long tmp2 = w1 - a[l].a;
            if (a[l].c < a[j].c && a[l].a <= w1 && w1 <= a[l].b &&
                d[i - 1][l][tmp2] != -1 &&
                d[i - 1][l][tmp2] + tmp >= d[i][j][t]) {
              d[i][j][t] = d[i - 1][l][tmp2] + tmp;
              par[i][j][t] = {l, tmp2};
            }
            if (w2 * k == tmp) swap(w1, w2);
          }
        }
      }
  long long mx(-1);
  pair<int, int> mxind = {0, 0};
  for (int i = n - 1; i < m; i++)
    for (int j = 0; j <= a[i].b - a[i].a; j++)
      if (d[n][i][j] > mx) {
        mx = d[n][i][j];
        mxind = {i, j};
      }
  if (mx == -1) {
    cout << "NO" << endl;
    return 0;
  }
  cout << "YES" << endl;
  pp(n, mxind.first, mxind.second);
  return 0;
}
