#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
const long long Max = 1000;
const long long size = 60;
long long dp[size][size][120];
long long id[size][size][120];
long long val[size][size][120];
;
struct NODE {
  long long a;
  long long b;
  long long c;
  long long idx;
} node[size];
bool cmp(struct NODE a, struct NODE b) { return a.c < b.c; }
int main() {
  long long n, m, K;
  cin >> n >> m >> K;
  for (long long i = 0; i < m; i++) {
    cin >> node[i].a >> node[i].b >> node[i].c;
    node[i].idx = i + 1;
  }
  sort(node, node + m, cmp);
  for (long long j = 0; j < m; j++) {
    for (long long k = 0; node[j].a + k <= node[j].b; k++) {
      dp[0][j][k] = node[j].a + k;
    }
  }
  for (long long i = 0; i < n - 1; i++) {
    for (long long j = 0; j < m; j++) {
      for (long long k = 0; node[j].a + k <= node[j].b; k++) {
        long long num = node[j].a + k;
        if (dp[i][j][k] != 0)
          for (long long nextj = j + 1; nextj < m; nextj++) {
            if (node[nextj].c == node[j].c) continue;
            if (node[nextj].a <= num + K && num + K <= node[nextj].b) {
              if (dp[i + 1][nextj][num + K - node[nextj].a] <
                  dp[i][j][k] + num + K) {
                dp[i + 1][nextj][num + K - node[nextj].a] =
                    dp[i][j][k] + num + K;
                id[i + 1][nextj][num + K - node[nextj].a] = j;
                val[i + 1][nextj][num + K - node[nextj].a] = k;
              }
            }
            if (node[nextj].a <= num * K && num * K <= node[nextj].b) {
              if (dp[i + 1][nextj][num * K - node[nextj].a] <
                  dp[i][j][k] + num * K) {
                dp[i + 1][nextj][num * K - node[nextj].a] =
                    dp[i][j][k] + num * K;
                id[i + 1][nextj][num * K - node[nextj].a] = j;
                val[i + 1][nextj][num * K - node[nextj].a] = k;
              }
            }
          }
      }
    }
  }
  long long finalind = -1, finalval = -1, ans = 0;
  for (long long j = 0; j < m; j++) {
    for (long long k = 0; node[j].a + k <= node[j].b; k++) {
      if (dp[n - 1][j][k] > ans) {
        ans = dp[n - 1][j][k];
        finalind = j;
        finalval = k;
      }
    }
  }
  if (ans == 0) {
    cout << "NO" << endl;
  } else {
    cout << "YES" << endl;
    vector<pair<long long, long long>> res;
    res.push_back(make_pair(finalind, node[finalind].a + finalval));
    for (long long i = n - 2; i >= 0; i--) {
      long long tmpind = id[i + 1][finalind][finalval];
      long long tmpval = val[i + 1][finalind][finalval];
      res.push_back(make_pair(tmpind, node[tmpind].a + tmpval));
      finalval = tmpval;
      finalind = tmpind;
    }
    long long len = res.size();
    for (long long i = len - 1; i >= 0; i--) {
      long long l = res[i].first;
      long long h = res[i].second;
      cout << node[l].idx << " " << h << endl;
    }
  }
}
