#include <bits/stdc++.h>
using namespace std;
int n, m, c;
long long dp[200][200][200];
pair<int, int> parent[200][200][200];
pair<pair<int, int>, pair<long long, long long> > x[200];
int main() {
  scanf("%d %d %d", &n, &m, &c);
  for (int i = 0; i < m; i++) {
    cin >> x[i].second.first >> x[i].second.second >> x[i].first.first;
    x[i].first.second = i;
  }
  sort(x, x + m);
  long long maxi = -1;
  int besti, bestj, bestk;
  for (int i = 0; i < m; i++) {
    for (int k = 0; k <= (x[i].second.second - x[i].second.first); k++) {
      dp[i][1][k] = x[i].second.first + k;
      parent[i][1][k].first = -1;
      if (n == 1 && dp[i][1][k] > maxi) {
        maxi = dp[i][1][k];
        besti = i;
        bestj = 1;
        bestk = k;
      }
    }
  }
  for (int i = 1; i < m; i++) {
    for (int j = 2; j <= n; j++) {
      for (int k = 0; k <= (x[i].second.second - x[i].second.first); k++) {
        long long rl = k + x[i].second.first;
        bool can = (rl % c == 0);
        for (int l = 0; l < i; l++) {
          if (x[l].first.first == x[i].first.first) continue;
          if (can) {
            int _2 = j - 1;
            long long _3 = rl / c - x[l].second.first;
            if (rl / c <= x[l].second.second && _3 >= 0 && dp[l][_2][_3] != 0) {
              if (dp[l][_2][_3] + rl > dp[i][j][k]) {
                dp[i][j][k] = dp[l][_2][_3] + rl;
                parent[i][j][k].first = l;
                parent[i][j][k].second = _3;
              }
            }
          }
          if (rl >= c) {
            int _2 = j - 1;
            long long _3 = rl - c - x[l].second.first;
            if (rl - c > x[l].second.second) continue;
            if (_3 >= 0 && dp[l][_2][_3] == 0) continue;
            if (_3 >= 0 && rl - c <= x[l].second.second) {
              if (dp[l][_2][_3] + rl > dp[i][j][k]) {
                dp[i][j][k] = dp[l][_2][_3] + rl;
                parent[i][j][k].first = l;
                parent[i][j][k].second = _3;
              }
            }
          }
        }
        if (j == n) {
          if (dp[i][j][k] > maxi) {
            maxi = dp[i][j][k];
            besti = i;
            bestj = j;
            bestk = k;
          }
        }
      }
    }
  }
  stack<pair<int, long long> > s;
  if (maxi <= 0) {
    cout << "NO\n";
    return 0;
  } else {
    cout << "YES\n";
  }
  while (besti >= 0) {
    s.push(make_pair(besti, bestk + x[besti].second.first));
    int t1 = besti;
    besti = parent[t1][bestj][bestk].first;
    bestk = parent[t1][bestj][bestk].second;
    bestj--;
  }
  while (!s.empty()) {
    cout << x[s.top().first].first.second + 1 << ' ' << s.top().second << '\n';
    s.pop();
  }
  return 0;
}
