#include <bits/stdc++.h>
using namespace std;
const int N = 55;
const int M = 105;
struct node {
  int c, id;
  long long a, b;
} p[N];
int n, m, k, pre[N][N][105][2];
long long dp[N][N][105];
bool cmp(const node &x, const node &y) { return x.c < y.c; }
void Print(int i, int s, int j) {
  int pos;
  if (s == 1) {
    cout << p[i].id << " " << p[i].a + j << endl;
    return;
  } else {
    pos = pre[i][s][j][0];
    if (pre[i][s][j][1] == 0)
      Print(pos, s - 1, (p[i].a + j) / k - p[pos].a);
    else
      Print(pos, s - 1, (p[i].a + j - k) - p[pos].a);
    cout << p[i].id << " " << p[i].a + j << endl;
  }
}
int main() {
  int i, j, s, q;
  long long tmp;
  memset(dp, -1, sizeof(dp));
  cin >> n >> m >> k;
  for (i = 1; i <= m; i++) {
    cin >> p[i].a >> p[i].b >> p[i].c;
    p[i].id = i;
  }
  sort(p + 1, p + m + 1, cmp);
  for (i = 1; i <= m; i++)
    for (j = 0; j < M && j <= p[i].b - p[i].a; j++) dp[i][1][j] = p[i].a + j;
  for (s = 1; s < n; s++)
    for (i = 1; i <= m; i++)
      for (j = 0; j < M && j <= p[i].b - p[i].a; j++) {
        if (dp[i][s][j] == -1 || j > p[i].b - p[i].a)
          continue;
        else {
          for (q = i + 1; q <= m; q++)
            if (p[q].c > p[i].c) {
              tmp = (p[i].a + j) * k;
              if (tmp >= p[q].a && tmp <= p[q].b) {
                if (dp[q][s + 1][tmp - p[q].a] < dp[i][s][j] + tmp) {
                  dp[q][s + 1][tmp - p[q].a] = dp[i][s][j] + tmp;
                  pre[q][s + 1][tmp - p[q].a][0] = i;
                  pre[q][s + 1][tmp - p[q].a][1] = 0;
                }
              }
              tmp = (p[i].a + j) + k;
              if (tmp >= p[q].a && tmp <= p[q].b) {
                if (dp[q][s + 1][tmp - p[q].a] < dp[i][s][j] + tmp) {
                  dp[q][s + 1][tmp - p[q].a] = dp[i][s][j] + tmp;
                  pre[q][s + 1][tmp - p[q].a][0] = i;
                  pre[q][s + 1][tmp - p[q].a][1] = 1;
                }
              }
            }
        }
      }
  tmp = -1;
  for (i = 1; i <= m; i++)
    for (j = 0; j < M; j++) tmp = max(tmp, dp[i][n][j]);
  if (tmp != -1) {
    printf("YES\n");
    bool flag = false;
    for (i = 1; i <= m; i++) {
      for (j = 0; j < M; j++)
        if (dp[i][n][j] == tmp) {
          Print(i, n, j);
          flag = true;
          break;
        }
      if (flag) break;
    }
  } else
    printf("NO\n");
  return 0;
}
