#include <bits/stdc++.h>
using namespace std;
long long n, m, c, i, j, s, i2, j2, mx;
long long A[51], B[51], C[51], M[51][101][51], S[51][101][51], P[51][101][51];
long long solve(long long i, long long j, long long k) {
  long long &res = M[i][j][k], p, x;
  if (res == -1) {
    if (k > 1) {
      res = LLONG_MIN;
      x = A[i] + j;
      for (p = 0; p < m; p++) {
        if (C[p] > C[i] && (x + c >= A[p] && x + c <= B[p]) &&
            solve(p, x + c - A[p], k - 1) > res) {
          res = solve(p, x + c - A[p], k - 1);
          P[i][j][k] = p;
          S[i][j][k] = x + c;
        }
        if (C[p] > C[i] && (x * c >= A[p] && x * c <= B[p]) &&
            solve(p, x * c - A[p], k - 1) > res) {
          res = solve(p, x * c - A[p], k - 1);
          P[i][j][k] = p;
          S[i][j][k] = x * c;
        }
      }
      if (res >= 0) res += j + A[i];
    } else
      res = j + A[i];
  }
  return res;
}
int main() {
  scanf("%I64d%I64d%I64d", &n, &m, &c);
  for (i = 0; i < m; i++) scanf("%I64d%I64d%I64d", &A[i], &B[i], &C[i]);
  memset(M, -1, sizeof M);
  for (i = 0; i < m; i++)
    for (j = A[i]; j <= B[i]; j++)
      if (solve(i, j - A[i], n) > mx) {
        mx = solve(i, j - A[i], n);
        i2 = i;
        j2 = j;
      }
  if (!mx) {
    printf("NO");
    return 0;
  }
  printf("YES\n");
  i = i2;
  j = j2;
  j -= A[i];
  while (n) {
    printf("%I64d %I64d\n", i + 1, j + A[i]);
    s = S[i][j][n];
    i = P[i][j][n];
    j = s - A[i];
    n--;
  }
  return 0;
}
