#include <bits/stdc++.h>
using namespace std;
struct Node {
  long long L, R;
  int C, index;
  bool operator<(const Node &a) const { return (C < a.C); }
} a[10000];
long long d[110][110][110];
bool calced[110][110][110];
int n, m, k;
long long Calc(int n, int m, int x) {
  if (n == 0) {
    return a[m].L + x;
  }
  if (m == 0) return -(1ll << 61);
  long long &ans = d[n][m][x];
  if (calced[n][m][x]) return ans;
  calced[n][m][x] = true;
  ans = -(1ll << 61);
  long long curX = x + a[m].L;
  for (int i = 0; i < m; ++i)
    if (a[i].C < a[m].C) {
      if (curX % k == 0 && a[i].L <= curX / k && curX / k <= a[i].R) {
        long long prevX = curX / k;
        if (Calc(n - 1, i, prevX - a[i].L) + curX > ans) {
          ans = Calc(n - 1, i, prevX - a[i].L) + curX;
        }
      }
      if (a[i].L <= curX - k && curX - k <= a[i].R) {
        long long prevX = curX - k;
        if (Calc(n - 1, i, prevX - a[i].L) + curX > ans) {
          ans = Calc(n - 1, i, prevX - a[i].L) + curX;
        }
      }
    }
  return ans;
}
void Print(int n, int m, int x) {
  if (n == 0) {
    cout << a[m].index << " " << a[m].L + x << endl;
    return;
  }
  long long ans = Calc(n, m, x);
  long long curX = x + a[m].L;
  for (int i = 0; i < m; ++i)
    if (a[i].C < a[m].C) {
      if (curX % k == 0 && a[i].L <= curX / k && curX / k <= a[i].R) {
        long long prevX = curX / k;
        if (Calc(n - 1, i, prevX - a[i].L) == ans - curX) {
          Print(n - 1, i, prevX - a[i].L);
          cout << a[m].index << " " << a[m].L + x << endl;
          return;
        }
      }
      if (a[i].L <= curX - k && curX - k <= a[i].R) {
        long long prevX = curX - k;
        if (Calc(n - 1, i, prevX - a[i].L) == ans - curX) {
          Print(n - 1, i, prevX - a[i].L);
          cout << a[m].index << " " << a[m].L + x << endl;
          return;
        }
      }
    }
}
int main() {
  cin >> n >> m >> k;
  for (int i = 0; i < m; ++i) {
    cin >> a[i].L >> a[i].R >> a[i].C;
    a[i].index = i + 1;
  }
  sort(a, a + m);
  memset(calced, 0, sizeof(calced));
  long long ans = -(1ll << 60), ansM, ansX;
  for (int i = 0; i < m; ++i) {
    for (long long j = a[i].L; j <= a[i].R; ++j)
      if (ans < Calc(n - 1, i, j - a[i].L)) {
        ans = Calc(n - 1, i, j - a[i].L);
        ansM = i;
        ansX = j - a[i].L;
      }
  }
  if (ans < 0) {
    puts("NO");
    return 0;
  }
  puts("YES");
  Print(n - 1, ansM, ansX);
  return 0;
}
