#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-9;
const int inf = (int)1e9;
const int MAX_N = 111;
struct sub {
  long long a, b;
  int c, num;
  sub(long long _a, long long _b, int _c, int _num) {
    a = _a, b = _b, c = _c, num = _num;
  }
  sub() {}
  bool operator<(const sub &S) const { return c < S.c; }
};
int n, m, k;
vector<sub> v;
long long dp[MAX_N / 2][MAX_N][MAX_N / 2];
bool visit[MAX_N / 2][MAX_N][MAX_N / 2];
pair<int, int> path[MAX_N / 2][MAX_N][MAX_N / 2];
long long rec(int prev, int delta, int here) {
  if (here == n) return 0;
  if (prev == ((int)v.size()) - 1) return -inf;
  long long &ref = dp[prev][delta][here];
  if (visit[prev][delta][here]) return ref;
  visit[prev][delta][here] = 1;
  ref = -inf;
  for (int i = prev + 1; i < ((int)v.size()); i++) {
    if (v[i].c == v[prev].c) continue;
    long long x[2];
    x[0] = (v[prev].a + delta) * k;
    x[1] = (v[prev].a + delta) + k;
    for (int j = 0; j < 2; j++) {
      if (x[j] >= v[i].a && x[j] <= v[i].b) {
        long long aux = rec(i, x[j] - v[i].a, here + 1);
        if (aux != -inf && aux + x[j] > ref) {
          ref = aux + x[j];
          path[prev][delta][here] = pair<int, int>(i, x[j] - v[i].a);
        }
      }
    }
  }
  return ref;
}
int main() {
  cin >> n >> m >> k;
  for (int i = 0; i < m; i++) {
    long long a, b;
    int c;
    cin >> a >> b >> c;
    v.push_back(sub(a, b, c, i + 1));
  }
  sort(v.begin(), v.end());
  long long ans = -inf;
  int x, y, z = 1;
  for (int i = 0; i < ((int)v.size()); i++) {
    for (long long j = v[i].a; j <= v[i].b; j++) {
      long long aux = rec(i, j - v[i].a, 1);
      if (aux != -inf && ans < j + aux) {
        ans = j + aux;
        x = i, y = (int)(j - v[i].a);
      }
    }
  }
  if (ans == -inf) {
    cout << "NO" << endl;
  } else {
    cout << "YES" << endl;
    while (z <= n) {
      cout << v[x].num << " " << y + v[x].a << endl;
      int tx = path[x][y][z].first;
      int ty = path[x][y][z].second;
      x = tx, y = ty, z++;
    }
  }
  return 0;
}
