#include <bits/stdc++.h>
using namespace std;
int n, m, k;
long long a[100], b[100], c[100], dp[64][64][128];
pair<int, int> pre[64][64][128];
void print(int i, int j, int k) {
  if (i > 0) print(i - 1, pre[i][j][k].first, pre[i][j][k].second);
  cout << j + 1 << ' ' << a[j] + k << endl;
}
void solve() {
  for (int i = 0; i < (int)(m); i++)
    for (int j = 0; j < (int)(b[i] - a[i] + 1); j++) dp[0][i][j] = a[i] + j;
  for (int i = 0; i < (int)(n - 1); i++)
    for (int j = 0; j < (int)(m); j++)
      for (int z = 0; z < (int)(b[j] - a[j] + 1); z++)
        if (dp[i][j][z]) {
          for (int q = 0; q < (int)(m); q++)
            if (c[j] < c[q]) {
              const long long cur = a[j] + z;
              if (a[q] <= cur * k && cur * k <= b[q]) {
                if (dp[i + 1][q][cur * k - a[q]] < dp[i][j][z] + cur * k) {
                  dp[i + 1][q][cur * k - a[q]] = dp[i][j][z] + cur * k;
                  pre[i + 1][q][cur * k - a[q]] = make_pair(j, z);
                }
              }
              if (a[q] <= cur + k && cur + k <= b[q]) {
                if (dp[i + 1][q][cur + k - a[q]] < dp[i][j][z] + cur + k) {
                  dp[i + 1][q][cur + k - a[q]] = dp[i][j][z] + cur + k;
                  pre[i + 1][q][cur + k - a[q]] = make_pair(j, z);
                }
              }
            }
        }
  long long mx = -1;
  pair<long long, int> ans = make_pair(-1, -1);
  for (int i = 0; i < (int)(m); i++)
    for (int j = 0; j < (int)(b[i] - a[i] + 1); j++) {
      if (mx < dp[n - 1][i][j]) {
        mx = dp[n - 1][i][j];
        ans = make_pair(a[i] + j, i);
      }
    }
  if (mx > 0) {
    cout << "YES" << endl;
    print(n - 1, ans.second, ans.first - a[ans.second]);
  } else {
    cout << "NO" << endl;
  }
}
int main() {
  cin >> n >> m >> k;
  for (int i = 0; i < (int)(m); i++) cin >> a[i] >> b[i] >> c[i];
  solve();
  return 0;
}
