#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
const int INF = 1e9;
const long long LINF = 2e18;
const int WOW = 40000;
const int NIL = 0;
const int dy[8] = {0, 0, -1, 1, 1, 1, -1, -1};
const int dx[8] = {1, -1, 0, 0, 1, -1, 1, -1};
const double PI = 2 * acos(0);
const int MAXN = 55, MAXM = 55, MAXK = 105;
int N, M, K;
long long a[MAXM], b[MAXM], c[MAXM];
long long memo[MAXN][MAXM][MAXK];
pair<int, int> pi[MAXN][MAXM][MAXK];
void recover(int i, int j, int k) {
  printf("%d %lld\n", j + 1, a[j] + k);
  if (i == N - 1) return;
  long long s = (a[j] + k) + K, m = (a[j] + k) * K;
  pair<int, int> t = pi[i][j][k];
  if (t.second)
    recover(i + 1, t.first, m - a[t.first]);
  else
    recover(i + 1, t.first, s - a[t.first]);
}
long long dp(int i, int j, int k) {
  if (i == N - 1) return a[j] + k;
  long long& ret = memo[i][j][k];
  if (ret != -1) return ret;
  ret = -LINF;
  long long s = (a[j] + k) + K, m = (a[j] + k) * K;
  for (int l = 0; l < M; ++l) {
    if (c[l] <= c[j]) continue;
    if (s >= a[l] && s <= b[l]) {
      long long t = dp(i + 1, l, s - a[l]);
      if (ret < t) {
        ret = t;
        pi[i][j][k] = {l, 0};
      }
    }
    if (m >= a[l] && m <= b[l]) {
      long long t = dp(i + 1, l, m - a[l]);
      if (ret < t) {
        ret = t;
        pi[i][j][k] = {l, 1};
      }
    }
  }
  if (ret == -LINF) return ret;
  return ret += a[j] + k;
}
int main() {
  scanf("%d%d%d", &N, &M, &K);
  for (int i = 0; i < M; ++i) scanf("%lld%lld%lld", &a[i], &b[i], &c[i]);
  memset(memo, -1, sizeof(memo));
  long long mx = -LINF, mx1 = -1, mx2 = -1;
  for (int i = 0; i < M; ++i) {
    for (int j = 0; j < b[i] - a[i] + 1; ++j) {
      if (mx < dp(0, i, j)) {
        mx = dp(0, i, j);
        mx1 = i, mx2 = j;
      }
    }
  }
  if (mx == -LINF)
    puts("NO");
  else {
    puts("YES");
    recover(0, int(mx1), int(mx2));
  }
}
