#include <bits/stdc++.h>
using namespace std;
int n, m, p;
map<int, vector<int> > mp;
const int maxn = 55, maxl = 105;
const long long inf = 1LL << 60;
long long dp[maxn][maxn][maxl];
long long a[maxn], b[maxn];
int c[maxn];
pair<int, int> pre[maxn][maxn][maxl];
inline void upd(int i, int j, long long k, long long value,
                pair<int, int> info) {
  if (a[j] <= k && k <= b[j]) {
    long long &res = dp[i][j][k - a[j]];
    if (res < value) {
      res = value;
      pre[i][j][k - a[j]] = info;
    }
  }
}
void printans(int i, int j, int _k) {
  if (i) printans(i - 1, pre[i][j][_k].first, pre[i][j][_k].second);
  cout << j + 1 << ' ' << a[j] + _k << endl;
}
int main(void) {
  ios::sync_with_stdio(false);
  cin >> n >> m >> p;
  for (int i = 0; i < (m); ++i) cin >> a[i] >> b[i] >> c[i];
  fill((long long *)dp, (long long *)dp + sizeof(dp) / sizeof(long long), -inf);
  for (int j = 0; j < (m); ++j)
    for (int k = 0; k < (int(b[j] - a[j] + 1)); ++k) dp[0][j][k] = a[j] + k;
  for (int i = 0; i < (n - 1); ++i)
    for (int j = 0; j < (m); ++j)
      for (int _k = 0; _k < (int(b[j] - a[j] + 1)); ++_k)
        if (dp[i][j][_k] != -inf) {
          long long k = a[j] + _k, cur = dp[i][j][_k];
          for (int nj = 0; nj < (m); ++nj)
            if (c[nj] > c[j]) {
              upd(i + 1, nj, k + p, cur + k + p, make_pair(j, _k));
              upd(i + 1, nj, k * p, cur + k * p, make_pair(j, _k));
            }
        }
  long long ans = -inf;
  int aj = -1, ak = -1;
  for (int j = 0; j < (m); ++j)
    for (int _k = 0; _k < (int(b[j] - a[j] + 1)); ++_k)
      if (ans < dp[n - 1][j][_k]) ans = dp[n - 1][aj = j][ak = _k];
  if (ans < 0)
    cout << "NO" << endl;
  else {
    cout << "YES" << endl;
    printans(n - 1, aj, ak);
  }
  return 0;
}
