#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
const long long INF = (1e9);
long long dp[((100) + 5)][((100) + 5)][((100) + 5)];
struct sub {
  long long ai, bi, ci, id;
} s[((100) + 5)];
struct chose {
  long long id, cnt;
  chose() {}
  chose(long long x, long long y) : id(x), cnt(y) {}
} pre[55][55][((100) + 5)], opt[((100) + 5)];
bool cmp(sub a, sub b) { return a.ci < b.ci; }
int main() {
  int n, m;
  long long d;
  scanf("%d%d%lld", &n, &m, &d);
  for (int i = 1; i <= m; i++) {
    scanf("%lld%lld%lld", &s[i].ai, &s[i].bi, &s[i].ci);
    s[i].id = i;
  }
  sort(s + 1, s + 1 + m, cmp);
  for (long long i = 1; i <= m; i++) {
    for (long long j = s[i].ai; j <= s[i].bi; j++) {
      dp[1][i][j - s[i].ai] = j;
    }
  }
  for (long long i = 1; i < n; i++) {
    for (long long j = i; j <= m && (m - j) >= (n - i); j++) {
      for (long long k = s[j].ai; k <= s[j].bi; k++) {
        long long cnt = dp[i][j][k - s[j].ai];
        if (cnt) {
          for (long long jj = j + 1; jj <= m; jj++) {
            if (s[j].ci == s[jj].ci) continue;
            if (k * d >= s[jj].ai && k * d <= s[jj].bi) {
              if (dp[i + 1][jj][k * d - s[jj].ai] < cnt + k * d) {
                dp[i + 1][jj][k * d - s[jj].ai] = cnt + k * d;
                pre[i + 1][jj][k * d - s[jj].ai] = chose(j, k - s[j].ai);
              }
            }
            if (k + d >= s[jj].ai && k + d <= s[jj].bi) {
              if (dp[i + 1][jj][k + d - s[jj].ai] < cnt + k + d) {
                dp[i + 1][jj][k + d - s[jj].ai] = cnt + k + d;
                pre[i + 1][jj][k + d - s[jj].ai] = chose(j, k - s[j].ai);
              }
            }
          }
        }
      }
    }
  }
  long long ans = 0;
  long long jj = 0, kk = 0;
  for (int i = n; i <= m; i++) {
    for (long long j = s[i].ai; j <= s[i].bi; j++) {
      if (ans < dp[n][i][j - s[i].ai]) {
        ans = dp[n][i][j - s[i].ai];
        jj = i;
        kk = j - s[i].ai;
      }
    }
  }
  if (ans) {
    printf("YES\n");
    int on = 0;
    chose now = chose(jj, kk);
    for (int i = n; i >= 1; i--) {
      opt[++on] = now;
      now = pre[i][now.id][now.cnt];
    }
    for (int i = n; i >= 1; i--) {
      printf("%lld %lld\n", s[opt[i].id].id, opt[i].cnt + s[opt[i].id].ai);
    }
  } else {
    printf("NO\n");
  }
  return 0;
}
