#include <bits/stdc++.h>
using namespace std;
const int N = 55;
struct A {
  long long l, r, c, t;
} a[55];
long long f[N][N][105];
struct B {
  long long x, y;
} t[N][N][105];
long long res[N][2];
bool cmp(const A &a, const A &b) { return a.c < b.c; }
int main() {
  long long m, n, o, i, j, k, p, ans, x, y;
  cin >> m >> n >> o;
  for (i = 1; i <= n; i++) {
    cin >> a[i].l >> a[i].r >> a[i].c;
    a[i].t = i;
  }
  sort(a + 1, a + n + 1, cmp);
  memset(f, -1, sizeof(f));
  for (i = 1; i <= n; i++)
    for (j = a[i].l; j <= a[i].r; j++) f[i][1][j - a[i].l] = j;
  for (i = 1; i < n; i++)
    for (j = 1; j <= i; j++)
      for (k = a[i].l; k <= a[i].r; k++)
        if (f[i][j][k - a[i].l] != -1) {
          for (p = i + 1; p <= n; p++)
            if (a[p].c > a[i].c) {
              x = k * o;
              if (x >= a[p].l && x <= a[p].r)
                if (f[i][j][k - a[i].l] + x > f[p][j + 1][x - a[p].l]) {
                  f[p][j + 1][x - a[p].l] = f[i][j][k - a[i].l] + x;
                  t[p][j + 1][x - a[p].l].x = i;
                  t[p][j + 1][x - a[p].l].y = k;
                }
              x = k + o;
              if (x >= a[p].l && x <= a[p].r)
                if (f[i][j][k - a[i].l] + x > f[p][j + 1][x - a[p].l]) {
                  f[p][j + 1][x - a[p].l] = f[i][j][k - a[i].l] + x;
                  t[p][j + 1][x - a[p].l].x = i;
                  t[p][j + 1][x - a[p].l].y = k;
                }
            }
        }
  ans = 0;
  for (i = 1; i <= n; i++)
    for (k = a[i].l; k <= a[i].r; k++)
      if (f[i][m][k - a[i].l] > ans) {
        ans = f[i][m][k - a[i].l];
        x = i;
        y = k;
      }
  if (ans == 0)
    printf("NO\n");
  else {
    printf("YES\n");
    long long l = 0, tx, ty;
    while (m > 0) {
      l++;
      res[l][0] = x;
      res[l][1] = y;
      long long tx = t[x][m][y - a[x].l].x, ty = t[x][m][y - a[x].l].y;
      x = tx;
      y = ty;
      m--;
    }
    for (i = l; i >= 1; i--) cout << a[res[i][0]].t << ' ' << res[i][1] << endl;
  }
}
