#include <bits/stdc++.h>
using namespace std;
const long long oo = 1e18;
int n, m, k;
long long dp[55][55][55][155];
pair<pair<int, int>, pair<long long, long long>> a[55];
long long solve(int idx = 1, int rem = n, int prv = 0, int offset = 0) {
  if (m - idx + 1 < rem) return -oo;
  if (rem <= 0) return 0;
  long long& ret = dp[idx][rem][prv][offset];
  if (~ret) return ret;
  ret = solve(idx + 1, rem, prv, offset);
  if (prv > 0) {
    if (a[idx].first.first > a[prv].first.first) {
      long long x = a[prv].second.first + offset;
      long long y[] = {x + k, x * k};
      for (int i = 0; i < 2; ++i) {
        if (y[i] >= a[idx].second.first && y[i] <= a[idx].second.second) {
          ret = max(
              ret,
              solve(idx + 1, rem - 1, idx, y[i] - a[idx].second.first) + y[i]);
        }
      }
    }
  } else
    for (long long i = a[idx].second.first; i <= a[idx].second.second; ++i) {
      ret = max(ret, solve(idx + 1, rem - 1, idx, i - a[idx].second.first) + i);
    }
  return ret;
}
void printAns(int idx = 1, int rem = n, int prv = 0, int offset = 0) {
  if (rem <= 0) return;
  long long res = solve(idx, rem, prv, offset);
  if (res == solve(idx + 1, rem, prv, offset)) {
    return printAns(idx + 1, rem, prv, offset);
  }
  if (prv > 0) {
    if (a[idx].first.first > a[prv].first.first) {
      long long x = a[prv].second.first + offset;
      long long y[] = {x + k, x * k};
      for (int i = 0; i < 2; ++i) {
        if (y[i] >= a[idx].second.first && y[i] <= a[idx].second.second) {
          if (res ==
              solve(idx + 1, rem - 1, idx, y[i] - a[idx].second.first) + y[i]) {
            printf("%d %lld\n", a[idx].first.second, y[i]);
            return printAns(idx + 1, rem - 1, idx, y[i] - a[idx].second.first);
          }
        }
      }
    }
  } else
    for (long long i = a[idx].second.first; i <= a[idx].second.second; ++i) {
      if (res == solve(idx + 1, rem - 1, idx, i - a[idx].second.first) + i) {
        printf("%d %lld\n", a[idx].first.second, i);
        return printAns(idx + 1, rem - 1, idx, i - a[idx].second.first);
      }
    }
}
int main() {
  cin >> n >> m >> k;
  for (int i = 1; i <= m; ++i) {
    cin >> a[i].second.first >> a[i].second.second >> a[i].first.first;
    a[i].first.second = i;
  }
  sort(a + 1, a + m + 1);
  memset(dp, -1, sizeof(dp));
  if (solve() < 0) {
    cout << "NO" << endl;
  } else {
    cout << "YES" << endl;
    printAns();
  }
  return 0;
}
