#include <bits/stdc++.h>
using namespace std;
struct subject {
  long long a, b;
  int c, r, s;
  bool operator<(subject const &T) const { return c < T.c; }
};
int n, m, rex, rey, fx[55][55][105], fy[55][55][105];
long long rat, val, tmp, old, dp[55][55][105], ret;
subject a[55];
void trace(int x, int y, int z) {
  if (y) trace(fx[x][y][z], y - 1, fy[x][y][z]);
  printf("%d %I64d\n", a[x].r, a[x].a + z);
}
int main() {
  scanf("%d%d%I64d", &n, &m, &rat);
  for (int i = 0; i < m; i++) {
    scanf("%I64d%I64d%d", &a[i].a, &a[i].b, &a[i].c);
    a[i].r = i + 1;
    a[i].s = a[i].b - a[i].a;
  }
  sort(a, a + m);
  memset(dp, -1, sizeof(dp));
  for (int i = 0; i < m; i++) {
    for (int j = 0; j <= a[i].s; j++) {
      dp[i][0][j] = val = a[i].a + j;
      for (int k = 1; k <= i; k++) {
        for (int l = 0; l < i; l++) {
          if (a[l].c == a[i].c) continue;
          if (val % rat == 0) {
            tmp = val / rat - a[l].a;
            if (0 <= tmp && tmp <= a[l].s) {
              old = dp[l][k - 1][tmp];
              if (old != -1 && dp[i][k][j] < old + val) {
                dp[i][k][j] = old + val;
                fx[i][k][j] = l;
                fy[i][k][j] = tmp;
              }
            }
          }
          if (val > rat) {
            tmp = val - rat - a[l].a;
            if (0 <= tmp && tmp <= a[l].s) {
              old = dp[l][k - 1][tmp];
              if (old != -1 && dp[i][k][j] < old + val) {
                dp[i][k][j] = old + val;
                fx[i][k][j] = l;
                fy[i][k][j] = tmp;
              }
            }
          }
        }
      }
      if (dp[i][n - 1][j] > ret) ret = dp[i][n - 1][j], rex = i, rey = j;
    }
  }
  if (ret) {
    printf("YES\n", ret);
    trace(rex, n - 1, rey);
  } else
    printf("NO\n");
  return 0;
}
