#include <bits/stdc++.h>
using namespace std;
struct Node {
  long long a, b;
  int c;
  int index;
  bool operator<(Node o) const { return c < o.c; }
};
Node node[55];
int n, m, k;
long long dp[55][55][102];
pair<int, int> path[55][55][102];
void init() {
  for (int i = 0; i < 55; i++) {
    for (int j = 0; j < 55; j++) {
      for (int k = 0; k < 102; k++) {
        dp[i][j][k] = -1;
      }
    }
  }
}
long long dfs(int d, int pre_index, int pre_task) {
  if (dp[d][pre_index][pre_task] != -1) {
    return dp[d][pre_index][pre_task];
  } else if (d == n) {
    path[d][pre_index][pre_task] = pair<int, int>(-1, -1);
    return dp[d][pre_index][pre_task] = 0;
  } else {
    long long ret = -2;
    long long pp = node[pre_index].a + pre_task;
    long long px = k + pp;
    long long py = k * pp;
    int index = pre_index + 1;
    while (node[index].c == node[pre_index].c) {
      index++;
    }
    for (; index < m; index++) {
      if (node[index].a <= px && px <= node[index].b) {
        long long tmp = dfs(d + 1, index, px - node[index].a);
        if (tmp != -2) {
          if (px + tmp > ret) {
            ret = px + tmp;
            path[d][pre_index][pre_task] =
                pair<int, int>(index, px - node[index].a);
          }
        }
      }
      if (node[index].a <= py && py <= node[index].b) {
        long long tmp = dfs(d + 1, index, py - node[index].a);
        if (tmp != -2) {
          if (py + tmp > ret) {
            ret = py + tmp;
            path[d][pre_index][pre_task] =
                pair<int, int>(index, py - node[index].a);
          }
        }
      }
    }
    return dp[d][pre_index][pre_task] = ret;
  }
}
void printOut(int d, int pre_index, int pre_task) {
  pair<int, int> cur = path[d][pre_index][pre_task];
  if (cur.first == -1) {
    return;
  } else {
    cout << node[cur.first].index << " " << 0LL + cur.second + node[cur.first].a
         << endl;
    printOut(d + 1, cur.first, cur.second);
  }
}
int main() {
  while (cin >> n >> m >> k) {
    for (int i = 0; i < m; i++) {
      cin >> node[i].a >> node[i].b >> node[i].c;
      node[i].index = i + 1;
    }
    sort(node, node + m);
    long long ans = -2;
    init();
    for (int index = 0; index < m; index++) {
      for (long long task = node[index].a; task <= node[index].b; task++) {
        long long tmp = dfs(1, index, task - node[index].a);
        if (tmp != -2) {
          if (task + tmp > ans) {
            ans = task + tmp;
            path[0][0][0] = pair<int, int>(index, task - node[index].a);
          }
        }
      }
    }
    if (ans == -2) {
      puts("NO");
    } else {
      puts("YES");
      printOut(0, 0, 0);
    }
  }
  return 0;
}
