#include <bits/stdc++.h>
using namespace std;
int n, m, k;
pair<pair<int, int>, pair<long long, long long> > arr[59];
long long dp[52][52][102];
long long const oo = 1e18;
long long solve(int c, int sb, long long p) {
  if (c == n) return 0;
  if (sb >= m) return -oo;
  if (p < arr[sb].second.first || p > arr[sb].second.second) return -oo;
  if (dp[c][sb][p - arr[sb].second.first] != -1)
    return dp[c][sb][(p - arr[sb].second.first)];
  long long maxi = -oo;
  for (long long q = (sb + 1); q < (m + 1); q++)
    if (arr[q].first.first > arr[sb].first.first) {
      maxi = max(maxi, solve(c + 1, q, p * k) + p);
      maxi = max(maxi, solve(c + 1, q, p + k) + p);
    }
  return dp[c][sb][(p - arr[sb].second.first)] = maxi;
}
vector<pair<int, long long> > V;
void print(int c, int sb, long long p) {
  if (c == n) return;
  if (sb >= m) return;
  if (p < arr[sb].second.first || p > arr[sb].second.second) return;
  long long opt = solve(c, sb, p);
  for (long long q = (sb + 1); q < (m + 1); q++) {
    if (opt == solve(c + 1, q, p * k) + p) {
      V.push_back(make_pair(arr[sb].first.second, p));
      print(c + 1, q, p * k);
      break;
    }
    if (opt == solve(c + 1, q, p + k) + p) {
      V.push_back(make_pair(arr[sb].first.second, p));
      print(c + 1, q, p + k);
      break;
    }
  }
}
int main() {
  while (cin >> n >> m >> k) {
    memset(dp, -1, sizeof(dp));
    for (long long i = (0); i < (m); i++) {
      cin >> arr[i].second.first >> arr[i].second.second >> arr[i].first.first;
      arr[i].first.second = i;
    }
    arr[m].first.first = 1000;
    sort(arr, arr + m);
    long long maxi = -oo;
    for (long long i = (0); i < (m); i++)
      for (long long j = (arr[i].second.first); j < (arr[i].second.second + 1);
           j++)
        maxi = max(maxi, solve(0, i, j));
    if (maxi >= 0) {
      cout << "YES" << endl;
      bool b = 0;
      for (long long i = (0); i < (m); i++) {
        for (long long j = (arr[i].second.first);
             j < (arr[i].second.second + 1); j++) {
          if (maxi == solve(0, i, j)) {
            print(0, i, j);
            b = 1;
            break;
          }
        }
        if (b) break;
      }
      for (long long i = (0); i < (V.size()); i++)
        cout << V[i].first + 1 << " " << V[i].second << endl;
    } else
      cout << "NO" << endl;
    V.clear();
  }
}
