#include <bits/stdc++.h>
using namespace std;
int n, m, k, c[50];
long long a[50], b[50];
long long dp[51][50][101];
bool vis[51][50][101];
long long calc(int n, int last, int x) {
  if (!n) return 0;
  if (!vis[n][last][x]) {
    vis[n][last][x] = true;
    dp[n][last][x] = -(1ll << 60);
    for (int i = 0; i < m; ++i)
      if (c[i] > c[last]) {
        if (a[last] + x + k >= a[i] && a[last] + x + k <= b[i])
          dp[n][last][x] =
              max(dp[n][last][x],
                  a[last] + x + k + calc(n - 1, i, a[last] + x + k - a[i]));
        if ((a[last] + x) * k >= a[i] && (a[last] + x) * k <= b[i])
          dp[n][last][x] =
              max(dp[n][last][x],
                  (a[last] + x) * k + calc(n - 1, i, (a[last] + x) * k - a[i]));
      }
  }
  return dp[n][last][x];
}
void print(int n, int last, int x) {
  if (!n) return;
  for (int i = 0; i < m; ++i)
    if (c[i] > c[last]) {
      if (a[last] + x + k >= a[i] && a[last] + x + k <= b[i] &&
          dp[n][last][x] ==
              a[last] + x + k + calc(n - 1, i, a[last] + x + k - a[i])) {
        printf("%d %lld\n", i + 1, a[last] + x + k);
        print(n - 1, i, a[last] + x + k - a[i]);
        return;
      }
      if ((a[last] + x) * k >= a[i] && (a[last] + x) * k <= b[i] &&
          dp[n][last][x] ==
              (a[last] + x) * k + calc(n - 1, i, (a[last] + x) * k - a[i])) {
        printf("%d %lld\n", i + 1, (a[last] + x) * k);
        print(n - 1, i, (a[last] + x) * k - a[i]);
        return;
      }
    }
}
int main() {
  scanf("%d%d%d", &n, &m, &k);
  for (int i = 0; i < m; ++i) scanf("%lld%lld%d", a + i, b + i, c + i);
  long long r = -1, J;
  int I;
  for (int i = 0; i < m; ++i)
    for (long long j = a[i]; j <= b[i]; ++j)
      if (r < j + calc(n - 1, i, j - a[i])) {
        r = j + calc(n - 1, i, j - a[i]);
        I = i;
        J = j;
      }
  if (r == -1)
    puts("NO");
  else {
    puts("YES");
    printf("%d %lld\n", I + 1, J);
    print(n - 1, I, J - a[I]);
  }
  return 0;
}
