#include <bits/stdc++.h>
using namespace std;
long long dp[50 + 3][50 + 3][100 + 3][50 + 3];
int n;
int m;
long long k;
pair<pair<long long, int>, pair<long long, long long> > a[50 + 3];
bool com(pair<pair<long long, int>, pair<long long, long long> > a,
         pair<pair<long long, int>, pair<long long, long long> > b) {
  return a.first.first < b.first.first;
}
long long solve(int i, int p, int x, int l) {
  if (i == m) return l == n ? 0 : -1000000000000000000ll;
  if (dp[i][p][x][l] != -1) return dp[i][p][x][l];
  long long mx = solve(i + 1, p, x, l);
  if (l == 0) {
    for (int j = 0; j <= a[i].second.second; j++) {
      mx = max(solve(i + 1, i, j, l + 1) + a[i].second.first + j, mx);
    }
  } else if (a[i].first.first > a[p].first.first) {
    long long pn = a[p].second.first + x;
    int x1 = k * pn - a[i].second.first;
    int x2 = k + pn - a[i].second.first;
    if (x1 >= 0 && x1 <= a[i].second.second)
      mx = max(solve(i + 1, i, x1, l + 1) + k * pn, mx);
    if (x2 >= 0 && x2 <= a[i].second.second)
      mx = max(solve(i + 1, i, x2, l + 1) + k + pn, mx);
  }
  return dp[i][p][x][l] = mx;
}
void trace(int i, int p, int x, int l) {
  if (i == m) return;
  long long o = solve(i, p, x, l);
  long long mx = solve(i + 1, p, x, l);
  if (mx == o) {
    trace(i + 1, p, x, l);
    return;
  }
  if (l == 0) {
    for (int j = 0; j <= a[i].second.second; j++) {
      mx = max(solve(i + 1, i, j, l + 1) + a[i].second.first + j, mx);
      if (mx == o) {
        cout << a[i].first.second << " " << a[i].second.first + j << endl;
        trace(i + 1, i, j, l + 1);
        return;
      }
    }
  } else if (a[i].first.first > a[p].first.first) {
    long long pn = a[p].second.first + x;
    int x1 = k * pn - a[i].second.first;
    int x2 = k + pn - a[i].second.first;
    if (x1 >= 0 && x1 <= a[i].second.second)
      mx = max(solve(i + 1, i, x1, l + 1) + k * pn, mx);
    if (mx == o) {
      cout << a[i].first.second << " " << k * pn << endl;
      trace(i + 1, i, x1, l + 1);
      return;
    }
    if (x2 >= 0 && x2 <= a[i].second.second)
      mx = max(solve(i + 1, i, x2, l + 1) + k + pn, mx);
    if (mx == o) {
      cout << a[i].first.second << " " << k + pn << endl;
      trace(i + 1, i, x2, l + 1);
      return;
    }
  }
}
int main() {
  cin >> n >> m >> k;
  long long t1, t2, t3;
  for (int i = 0; i < m; i++) {
    cin >> t1 >> t2 >> t3;
    a[i] = make_pair(make_pair(t3, i + 1), make_pair(t1, t2 - t1));
  }
  sort(a, a + m, com);
  memset(dp, -1, sizeof dp);
  long long k = solve(0, 0, 0, 0);
  if (k <= 0)
    cout << "NO";
  else {
    cout << "YES" << endl;
    trace(0, 0, 0, 0);
  }
}
