#include <bits/stdc++.h>
using namespace std;
const int MAXN = 55;
const int MAXM = 105;
const int inf = 0x3f3f3f3fLL;
struct NODE {
  long long a, b;
  int c, id;
};
struct ANS {
  int prei, prej, prek;
  long long val;
  ANS() {}
  ANS(int _i, int _j, int _k, long long _val)
      : prei(_i), prej(_j), prek(_k), val(_val) {}
};
NODE a[MAXN];
long long d[MAXN][MAXN][MAXM];
ANS pre[MAXN][MAXN][MAXM];
bool cmp(NODE a, NODE b) { return a.c < b.c; }
void update(int i, int j, int k, int x, int y, int z, long long val) {
  if (j == y) {
    j = y;
  }
  if (d[i][j][k] == -1 || d[i][j][k] < d[x][y][z] + val) {
    d[i][j][k] = d[x][y][z] + val;
    pre[i][j][k] = ANS(x, y, z, val);
  }
}
void printans(int i, int j, int k) {
  if (i == 0) return;
  printans(i - 1, pre[i][j][k].prej, pre[i][j][k].prek);
  printf("%d %I64d\n", a[j].id, pre[i][j][k].val);
}
void solved(int cas) {
  int n, m;
  long long K;
  scanf("%d %d %I64d", &m, &n, &K);
  for (int i = 1; i <= n; i++) {
    scanf("%I64d %I64d %d", &a[i].a, &a[i].b, &a[i].c);
    a[i].id = i;
  }
  sort(a + 1, a + n + 1, cmp);
  memset(d, -1, sizeof(d));
  a[0].a = a[0].b = 0;
  for (int i = 1; i <= n; i++)
    for (long long j = a[i].a; j <= a[i].b; j++) {
      d[1][i][j - a[i].a] = j;
      pre[1][i][j - a[i].a] = ANS(0, -1, -1, j);
    }
  for (int i = 1; i < m; i++) {
    for (int j = i; j <= n; j++) {
      for (int k = 0; k <= a[j].b - a[j].a; k++) {
        if (d[i][j][k] == -1) continue;
        long long lastnum = a[j].a + k;
        for (int l = j + 1; l <= n; l++) {
          if (a[l].c == a[j].c) continue;
          long long temp = lastnum + K;
          if (temp >= a[l].a && temp <= a[l].b)
            update(i + 1, l, temp - a[l].a, i, j, k, temp);
          temp = lastnum * K;
          if (temp >= a[l].a && temp <= a[l].b)
            update(i + 1, l, temp - a[l].a, i, j, k, temp);
        }
      }
    }
  }
  long long ans = -1;
  int ansi, ansj;
  for (int i = m; i <= n; i++)
    for (int j = 0; j <= 100; j++) {
      if (d[m][i][j] > ans) {
        ans = d[m][i][j];
        ansi = i;
        ansj = j;
      }
    }
  if (ans == -1)
    printf("NO\n");
  else {
    printf("YES\n");
    printans(m, ansi, ansj);
  }
}
int main() {
  int nT = 1;
  for (int i = 1; i <= nT; i++) solved(i);
}
