#include <bits/stdc++.h>
using namespace std;
const long long oo = 2e18;
pair<pair<long long, long long>, pair<long long, long long>> a[105];
long long dp[52][52][52][102];
long long trace[52][52][52][102];
long long n, m, k;
long long solve(long long num, long long i, long long j, long long x) {
  if (num == n) return dp[num][i][j][x] = 0;
  if ((n - num) > (m - i + 1)) return -oo;
  long long &res = dp[num][i][j][x];
  long long &t = trace[num][i][j][x];
  if (res != -oo) return res;
  res++;
  if (res < solve(num, i + 1, j, x)) {
    res = dp[num][i + 1][j][x];
    t = 0;
  }
  if (num == 0) {
    for (long long val = a[i].second.first; val <= a[i].second.second; val++) {
      long long xx = val - a[i].second.first;
      if (res < solve(num + 1, i + 1, i, xx) + val) {
        res = dp[num + 1][i + 1][i][xx] + val;
        t = val;
      }
    }
  }
  if (j != 0 && a[i].first.first != a[j].first.first) {
    long long val = x + a[j].second.first;
    if (a[i].second.first <= (val + k) && (val + k) <= a[i].second.second) {
      long long xx = val + k - a[i].second.first;
      if (res < solve(num + 1, i + 1, i, xx) + (val + k)) {
        res = dp[num + 1][i + 1][i][xx] + (val + k);
        t = (val + k);
      }
    }
    if (a[i].second.first <= (val * k) && (val * k) <= a[i].second.second) {
      long long xx = (val * k) - a[i].second.first;
      if (res < solve(num + 1, i + 1, i, xx) + (val * k)) {
        res = dp[num + 1][i + 1][i][xx] + (val * k);
        t = (val * k);
      }
    }
  }
  return res;
}
signed main() {
  cin >> n >> m >> k;
  for (long long i = 1; i <= m; i++) {
    cin >> a[i].second.first >> a[i].second.second >> a[i].first.first;
    a[i].first.second = i;
  }
  sort(a + 1, a + m + 1);
  for (long long num = 0; num <= n; num++)
    for (long long i = 1; i <= m; i++)
      for (long long j = 0; j <= m; j++)
        for (long long x = 0; x <= 100; x++) {
          dp[num][i][j][x] = -oo;
        }
  if (solve(0, 1, 0, 0) <= 0) return cout << "NO\n", 0;
  cout << "YES\n";
  long long num = 0;
  long long j = 0;
  long long x = 0;
  for (long long i = 1; i <= m; i++) {
    long long t = trace[num][i][j][x];
    if (t != 0) {
      cout << a[i].first.second << " " << t << "\n";
      x = t - a[i].second.first;
      j = i;
      num++;
    }
  }
  return 0;
}
