#include <bits/stdc++.h>
using namespace std;
template <class T>
bool umin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool umax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
vector<pair<pair<long long, long long>, pair<long long, long long> > > v;
long long dp[52][104][52][52], n, m, k;
long long rec(long long last, long long cof, long long pos, long long take) {
  if (take > n) return -1000000000000000007;
  if (pos > m) {
    if (take == n) return 0;
    return -1000000000000000007;
  }
  long long& ret = dp[last][cof][pos][take];
  if (~ret) return ret;
  ret = -1000000000000000007;
  umax(ret, rec(last, cof, pos + 1, take));
  long long l = v[pos].first.second;
  long long r = v[pos].second.first;
  long long now = v[pos].first.first;
  if (!last) {
    for (long long i = l; i <= r; i++)
      umax(ret, rec(pos, i - l, pos + 1, take + 1) + i);
  } else {
    if (v[last].first.first < now) {
      long long need = v[last].first.second + cof;
      if (need + k >= l and need + k <= r)
        umax(ret, rec(pos, (need + k) - l, pos + 1, take + 1) + need + k);
      if (need * k >= l and need * k <= r)
        umax(ret, rec(pos, (need * k) - l, pos + 1, take + 1) + need * k);
    }
  }
  return ret;
}
void go(long long last, long long cof, long long pos, long long take) {
  if (pos > m) return;
  long long ret = dp[last][cof][pos][take];
  if (ret == rec(last, cof, pos + 1, take))
    go(last, cof, pos + 1, take);
  else {
    long long l = v[pos].first.second;
    long long r = v[pos].second.first;
    printf("%lld", v[pos].second.second);
    if (!last) {
      for (long long i = l; i <= r; i++)
        if (ret == rec(pos, i - l, pos + 1, take + 1) + i) {
          printf(" %lld\n", i);
          go(pos, i - l, pos + 1, take + 1);
        }
    } else {
      long long need = v[last].first.second + cof;
      if (need + k >= l and need + k <= r and
          ret == rec(pos, (need + k) - l, pos + 1, take + 1) + need + k) {
        printf(" %lld\n", need + k);
        go(pos, (need + k) - l, pos + 1, take + 1);
      }
      if (need * k >= l and need * k <= r and
          ret == rec(pos, (need * k) - l, pos + 1, take + 1) + need * k) {
        printf(" %lld\n", need * k);
        go(pos, (need * k) - l, pos + 1, take + 1);
      }
    }
  }
}
int main() {
  memset(dp, -1, sizeof dp);
  scanf("%lld%lld%lld", &n, &m, &k);
  v.push_back(make_pair(make_pair(0, 0), make_pair(0, 0)));
  for (long long i = 1; i <= m; i++) {
    long long a, b, c;
    scanf("%lld%lld%lld", &a, &b, &c);
    v.push_back(make_pair(make_pair(c, a), make_pair(b, i)));
  }
  sort(v.begin(), v.end());
  if (rec(0, 0, 1, 0) < 0) {
    printf("NO\n");
    return 0;
  }
  printf("YES\n");
  go(0, 0, 1, 0);
  return 0;
}
