#include <bits/stdc++.h>
using namespace std;
struct PAR {
  int last_ix, last_len;
  long long tot;
};
struct PAR par[51][51][101];
struct sub {
  long long a, b;
  int c;
  int index;
};
struct sub mx[101];
bool cmp(const struct sub a, const struct sub b) { return a.c < b.c; }
int main() {
  int n, m, K;
  cin >> n >> m >> K;
  for (int i = 0; i < m; i++) {
    cin >> mx[i].a >> mx[i].b >> mx[i].c;
    mx[i].index = i + 1;
  }
  sort(mx, mx + m, cmp);
  for (int i = 0; i < m; i++) {
    int up = mx[i].b - mx[i].a;
    for (int k = 0; k <= up; k++) {
      par[i][1][k].tot = mx[i].a + k;
    }
  }
  int index = -1, len;
  if (n == 1) {
    long long maxv = 0;
    int index = 0;
    for (int i = 0; i < m; i++) {
      if (mx[i].b > maxv) {
        maxv = mx[i].b;
        index = mx[i].index;
      }
    }
    cout << "YES" << endl;
    cout << index << " " << maxv << endl;
    return 0;
  }
  long long tot = 0;
  for (int cur = 0; cur < m; cur++) {
    long long a = mx[cur].a, b = mx[cur].b;
    for (int i = 0; i < cur; i++) {
      if (mx[i].c == mx[cur].c) continue;
      for (int j = 1; j < n; j++) {
        int up = mx[i].b - mx[i].a;
        for (int k = 0; k <= up; k++) {
          if (par[i][j][k].tot) {
            long long kk = (k + mx[i].a) + K;
            if (kk >= a && kk <= b) {
              if (par[i][j][k].tot + kk > par[cur][j + 1][kk - a].tot) {
                par[cur][j + 1][kk - a].tot = par[i][j][k].tot + kk;
                par[cur][j + 1][kk - a].last_ix = i;
                par[cur][j + 1][kk - a].last_len = k;
                if (j + 1 == n) {
                  if (par[cur][j + 1][kk - a].tot > tot) {
                    tot = par[cur][j + 1][kk - a].tot;
                    index = cur;
                    len = kk - a;
                  }
                }
              }
            }
            kk = (k + mx[i].a) * K;
            if (kk >= a && kk <= b) {
              if (par[i][j][k].tot + kk > par[cur][j + 1][kk - a].tot) {
                par[cur][j + 1][kk - a].tot = par[i][j][k].tot + kk;
                par[cur][j + 1][kk - a].last_ix = i;
                par[cur][j + 1][kk - a].last_len = k;
                if (j + 1 == n) {
                  if (par[cur][j + 1][kk - a].tot > tot) {
                    tot = par[cur][j + 1][kk - a].tot;
                    index = cur;
                    len = kk - a;
                  }
                }
              }
            }
          }
        }
      }
    }
  }
  struct out {
    int index;
    long long len;
  } outs[101];
  if (index != -1) {
    puts("YES");
    int nn = n;
    while (true) {
      int tlen = len;
      outs[n].index = index, outs[n].len = len + mx[index].a;
      len = par[index][n][tlen].last_len;
      index = par[index][n--][tlen].last_ix;
      if (n == 0) break;
    }
    for (int i = 1; i <= nn; i++) {
      cout << mx[outs[i].index].index << " " << outs[i].len << endl;
    }
  } else
    puts("NO");
  return 0;
}
