#include <bits/stdc++.h>
using namespace std;
struct rec {
  unsigned long long n, c;
  unsigned long long a, b;
};
bool operator<(const rec &a, const rec &b) { return a.c < b.c; }
rec X[50];
unsigned long long T[50][50][101];
char W[50][50][101];
char V[50][50][101];
void print(int n, int i, int j) {
  if (n) {
    --n;
    print(n, W[n][i][j], V[n][i][j]);
    cout << X[i].n << " " << X[i].a + j << endl;
  }
}
int main(void) {
  unsigned long long i, j, r, n, m, k, t, y;
  cin >> n >> m >> k;
  for (i = 0; i < m; i++) {
    cin >> X[i].a >> X[i].b >> X[i].c;
    X[i].n = i + 1;
  }
  sort(X, X + m);
  for (i = 0; i < n; i++)
    for (j = 0; j < m; j++)
      for (r = 0; r <= 100; r++) T[i][j][r] = 0;
  for (i = 0; i < m; i++) {
    for (j = X[i].a; j <= X[i].b; j++) T[0][i][j - X[i].a] = j;
  }
  for (r = 1; r < n; r++) {
    for (i = r; i < m; i++) {
      for (t = r - 1; t < i; t++) {
        if (X[t].c < X[i].c) {
          for (j = X[i].a; j <= X[i].b; j++) {
            if (j > k) {
              y = j - k;
              if (y <= X[t].b && y >= X[t].a && T[r - 1][t][y - X[t].a] > 0) {
                if (T[r][i][j - X[i].a] < T[r - 1][t][y - X[t].a] + j) {
                  T[r][i][j - X[i].a] = T[r - 1][t][y - X[t].a] + j;
                  W[r][i][j - X[i].a] = t;
                  V[r][i][j - X[i].a] = y - X[t].a;
                }
              }
            }
            if (j % k == 0) {
              y = j / k;
              if (y <= X[t].b && y >= X[t].a && T[r - 1][t][y - X[t].a] > 0) {
                if (T[r][i][j - X[i].a] < T[r - 1][t][y - X[t].a] + j) {
                  T[r][i][j - X[i].a] = T[r - 1][t][y - X[t].a] + j;
                  W[r][i][j - X[i].a] = t;
                  V[r][i][j - X[i].a] = y - X[t].a;
                }
              }
            }
          }
        }
      }
    }
  }
  unsigned long long imax, jmax;
  y = 0;
  for (i = 0; i < m; i++)
    for (j = 0; j <= 100; j++)
      if (T[n - 1][i][j] > y) y = T[n - 1][imax = i][jmax = j];
  if (y > 0) {
    cout << "YES" << endl;
    print(n, imax, jmax);
  } else
    cout << "NO";
  return 0;
}
