#include <bits/stdc++.h>
using namespace std;
struct mb {
  long long a, b;
  int c;
};
long long dp[55][105][55];
pair<int, int> way[55][105][55];
mb a[55];
int n, m, k;
void cal(int id, int cur, int len) {
  if (len == n) {
    dp[id][cur][len] = cur + a[id].a;
    return;
  }
  if (dp[id][cur][len] != -1) return;
  long long res = 0;
  long long val = cur + a[id].a;
  for (int i = 0; i < m; i++)
    if (a[i].c > a[id].c) {
      if (val * k >= a[i].a && val * k <= a[i].b) {
        cal(i, val * k - a[i].a, len + 1);
        res = max(res, dp[i][val * k - a[i].a][len + 1]);
        if (res == dp[i][val * k - a[i].a][len + 1])
          way[id][cur][len] = {i, val * k - a[i].a};
      }
      if (val + k >= a[i].a && val + k <= a[i].b) {
        cal(i, val + k - a[i].a, len + 1);
        res = max(res, dp[i][val + k - a[i].a][len + 1]);
        if (res == dp[i][val + k - a[i].a][len + 1])
          way[id][cur][len] = {i, val + k - a[i].a};
      }
    }
  if (res == 0)
    dp[id][cur][len] = 0;
  else
    dp[id][cur][len] = res + cur + a[id].a;
  return;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  for (int i = 0; i < 55; i++)
    for (int t = 0; t < 105; t++) fill(dp[i][t], dp[i][t] + 55, -1);
  cin >> n >> m >> k;
  for (int i = 0; i < m; i++) cin >> a[i].a >> a[i].b >> a[i].c;
  for (int i = 0; i < m; i++)
    for (long long t = a[i].a; t <= a[i].b; t++) cal(i, t - a[i].a, 1);
  long long maxx = 0, max_i = 0, max_t = 0;
  for (int i = 0; i < m; i++)
    for (long long t = a[i].a; t <= a[i].b; t++) {
      maxx = max(maxx, dp[i][t - a[i].a][1]);
      if (maxx == dp[i][t - a[i].a][1]) {
        max_i = i;
        max_t = t - a[i].a;
      }
    }
  if (maxx == 0) {
    cout << "NO\n";
    return 0;
  }
  cout << "YES\n";
  for (int i = 1; i <= n; i++) {
    cout << max_i + 1 << " " << a[max_i].a + max_t << "\n";
    int cp = max_i;
    max_i = way[max_i][max_t][i].first;
    max_t = way[cp][max_t][i].second;
  }
}
