#include <bits/stdc++.h>
using namespace std;
int n, m, k;
long long a[60], b[60];
int c[100];
long long mem[60][60][110];
long long nxt[60][60][110], nxta[60][60][110];
long long dp(int i, int cnt, long long amt) {
  if (amt < a[i] || amt > b[i]) return -2;
  if (cnt == 1) return amt;
  int nrm = amt - a[i];
  if (mem[i][cnt][nrm] != -1) {
    return mem[i][cnt][nrm];
  }
  long long mx = -2, t;
  for (int j = 0; j < m; j++) {
    if (c[j] > c[i]) {
      t = dp(j, cnt - 1, amt + k);
      if (t > mx) {
        mx = t;
        nxt[i][cnt][nrm] = j;
        nxta[i][cnt][nrm] = amt + k;
      }
      t = dp(j, cnt - 1, amt * k);
      if (t > mx) {
        mx = t;
        nxt[i][cnt][nrm] = j;
        nxta[i][cnt][nrm] = amt * k;
      }
    }
  }
  if (mx != -2) {
    mx += amt;
  }
  return mem[i][cnt][nrm] = mx;
}
int main() {
  memset(mem, -1, sizeof(mem));
  cin >> n >> m >> k;
  for (int i = 0; i < m; i++) {
    cin >> a[i] >> b[i] >> c[i];
  }
  long long mx = -2, mxi, mxa;
  for (int i = 0; i < m; i++) {
    for (long long f = a[i]; f <= b[i]; f++) {
      long long t = dp(i, n, f);
      if (t > mx) {
        mx = t;
        mxi = i;
        mxa = f;
      }
    }
  }
  if (mx == -2) {
    cout << "NO";
    return 0;
  }
  cout << "YES" << endl;
  for (int i = n; i; i--) {
    cout << mxi + 1 << ' ' << mxa << endl;
    long long ti = nxt[mxi][i][mxa - a[mxi]], ta = nxta[mxi][i][mxa - a[mxi]];
    mxi = ti;
    mxa = ta;
  }
}
