#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
const int INF = 1000000007;
const long long INF2 = 1000000007LL * 1000000007LL;
const long double EPS = 1e-9;
const int SIZE = 200010;
mt19937 rng(time(0));
uniform_int_distribution<int> uid(-1000000000, 1000000000);
int n, m;
long long k;
struct str {
  int index, diff;
  long long l, r;
  str() {}
} task[60];
long long d[60][60][110];
bool u[60][60][110];
pair<int, int> nxt[60][60][110];
long long rec(int day, int subj, int delta) {
  if (u[day][subj][delta]) return d[day][subj][delta];
  if (day == n - 1) {
    return delta + task[subj].l;
  }
  u[day][subj][delta] = 1;
  d[day][subj][delta] = -1;
  long long cnt = task[subj].l + delta;
  for (int i = subj + 1; i < m; ++i) {
    if (task[i].diff == task[subj].diff) continue;
    long long cntNxt = cnt + k;
    if (cntNxt >= task[i].l && cntNxt <= task[i].r) {
      long long res = rec(day + 1, i, cntNxt - task[i].l);
      if (res > d[day][subj][delta]) {
        d[day][subj][delta] = res;
        nxt[day][subj][delta] = {i, cntNxt - task[i].l};
      }
    }
    cntNxt = cnt * k;
    if (cntNxt >= task[i].l && cntNxt <= task[i].r) {
      long long res = rec(day + 1, i, cntNxt - task[i].l);
      if (res > d[day][subj][delta]) {
        d[day][subj][delta] = res;
        nxt[day][subj][delta] = {i, cntNxt - task[i].l};
      }
    }
  }
  if (d[day][subj][delta] != -1) d[day][subj][delta] += delta + task[subj].l;
  return d[day][subj][delta];
}
pair<int, int> start;
long long ans = -1;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m >> k;
  for (int i = 0; i < m; ++i) {
    cin >> task[i].l >> task[i].r >> task[i].diff;
    task[i].index = i + 1;
  }
  sort(task, task + m, [](const str& a, const str& b) {
    return (a.diff == b.diff ? a.index < b.index : a.diff < b.diff);
  });
  for (int i = 0; i < m; ++i) {
    for (long long j = task[i].l; j <= task[i].r; ++j) {
      long long res = rec(0, i, j - task[i].l);
      if (res > ans) {
        ans = res;
        start = {i, j - task[i].l};
      }
    }
  }
  if (ans == -1) {
    cout << "NO";
    return 0;
  }
  cout << "YES\n";
  cout << task[start.first].index << ' ' << start.second + task[start.first].l
       << "\n";
  for (int rep_iter = 0; rep_iter < n - 1; ++rep_iter) {
    start = nxt[rep_iter][start.first][start.second];
    cout << task[start.first].index << ' ' << start.second + task[start.first].l
         << "\n";
  }
  return 0;
}
