#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9 + 10;
const long long int INFLL = 1e18 + 10;
const long double EPS = 1e-8;
const long double EPSLD = 1e-14;
const long long int MOD = 1e9 + 7;
template <class T>
T &chmin(T &a, const T &b) {
  return a = min(a, b);
}
template <class T>
T &chmax(T &a, const T &b) {
  return a = max(a, b);
}
const int MAX_N = 128;
long long int n, m, par;
long long int dp[MAX_N][MAX_N][MAX_N];
pair<long long int, long long int> pr[MAX_N][MAX_N][MAX_N];
pair<pair<long long int, long long int>, pair<long long int, long long int> >
    subject[MAX_N];
int main() {
  scanf("%lld %lld %lld", &n, &m, &par);
  for (int i = (0); i < (int)(m); i++)
    scanf("%lld %lld %lld", &subject[i].second.first, &subject[i].second.second,
          &subject[i].first.first);
  for (int i = (0); i < (int)(m); i++) subject[i].first.second = i + 1;
  sort(subject, subject + m);
  for (int i = (0); i < (int)(MAX_N); i++)
    for (int j = (0); j < (int)(MAX_N); j++)
      for (int k = (0); k < (int)(MAX_N); k++) dp[i][j][k] = -INFLL;
  for (int i = (0); i < (int)(m); i++)
    for (int j = (0);
         j < (int)(subject[i].second.second - subject[i].second.first + 1);
         j++) {
      dp[1][i][j] = subject[i].second.first + j;
      pr[1][i][j] = pair<long long int, long long int>(-1, -1);
    }
  for (int i = (1); i < (int)(n); i++)
    for (int j = (0); j < (int)(m); j++)
      for (int k = (0); k < (int)(MAX_N); k++)
        for (int l = (j + 1); l < (int)(m); l++) {
          long long int cur_task = subject[j].second.first + k;
          if (subject[l].first.first > subject[j].first.first) {
            long long int next_task = cur_task + par;
            if (subject[l].second.first <= next_task &&
                next_task <= subject[l].second.second) {
              if (dp[i + 1][l][next_task - subject[l].second.first] <
                  dp[i][j][k] + next_task) {
                dp[i + 1][l][next_task - subject[l].second.first] =
                    dp[i][j][k] + next_task;
                pr[i + 1][l][next_task - subject[l].second.first] =
                    pair<long long int, long long int>(j, k);
              }
            }
            next_task = cur_task * par;
            if (subject[l].second.first <= next_task &&
                next_task <= subject[l].second.second) {
              if (dp[i + 1][l][next_task - subject[l].second.first] <
                  dp[i][j][k] + next_task) {
                dp[i + 1][l][next_task - subject[l].second.first] =
                    dp[i][j][k] + next_task;
                pr[i + 1][l][next_task - subject[l].second.first] =
                    pair<long long int, long long int>(j, k);
              }
            }
          }
        }
  long long int res = -1;
  pair<long long int, long long int> p =
      pair<long long int, long long int>(-1, -1);
  for (int j = (0); j < (int)(m); j++)
    for (int k = (0); k < (int)(MAX_N); k++)
      if (res < dp[n][j][k]) {
        res = dp[n][j][k];
        p = pair<long long int, long long int>(j, k);
      }
  if (res < 0) return puts("NO");
  vector<pair<long long int, long long int> > ans(0);
  while (p != pair<long long int, long long int>(-1, -1)) {
    ans.emplace_back(subject[p.first].first.second,
                     subject[p.first].second.first + p.second);
    p = pr[n--][p.first][p.second];
  }
  reverse((ans).begin(), (ans).end());
  printf("YES\n");
  for (auto &w : ans) printf("%lld %lld\n", w.first, w.second);
  return 0;
}
