#include <bits/stdc++.h>
using namespace std;
struct nd {
  long long a, b;
  int c, id;
};
bool compare(nd n1, nd n2) { return n1.c < n2.c; }
pair<long long, pair<int, int> > dp[53][53][105];
const pair<long long, pair<int, int> > nul = make_pair(-1, make_pair(-1, -1));
nd inp[55];
int m, K;
long long maxLL(long long a, long long b) { return a > b ? a : b; }
pair<long long, pair<int, int> > compute(int id, int days, long long diff) {
  if (dp[id][days][diff] != nul) return dp[id][days][diff];
  long long ex = inp[id].a + diff;
  if (days == 1) return dp[id][days][diff] = make_pair(ex, make_pair(-1, -1));
  long long prev = -1;
  if (ex - K < 0) return nul;
  vector<long long> v;
  v.push_back(ex - K);
  if (ex % K == 0) v.push_back(ex / K);
  long long maxi = -1, prevdiff = -1;
  int pos = -1;
  for (int i = 0; inp[i].c < inp[id].c; ++i) {
    for (typeof((v).begin()) it = (v).begin(); it != (v).end(); it++) {
      prev = *it;
      long long cdiff = -1;
      if (prev < inp[i].a || prev > inp[i].b) continue;
      cdiff = prev - inp[i].a;
      long long tmp = dp[i][days - 1][cdiff].first;
      if (tmp > maxi) {
        maxi = tmp;
        pos = i;
        prevdiff = cdiff;
      }
    }
  }
  if (maxi == -1) return nul;
  return dp[id][days][diff] =
             make_pair(maxi + ex, make_pair(pos, (int)(prevdiff)));
}
int main() {
  int n, k, i, j;
  scanf("%d", &n);
  scanf("%d", &m);
  scanf("%d", &K);
  for (i = 0; i <= m; ++i)
    for (k = 0; k <= n; ++k)
      for (j = 0; j <= 100; ++j) dp[i][k][j] = nul;
  for (i = 0; i < m; ++i) {
    long long aa, bb;
    int cc;
    cin >> aa;
    cin >> bb;
    scanf("%d", &cc);
    inp[i] = (nd){aa, bb, cc, i + 1};
  }
  sort(inp, inp + m, compare);
  for (k = 1; k <= n; ++k)
    for (i = 0; i < m; ++i)
      for (long long j = inp[i].a; j <= inp[i].b; ++j)
        dp[i][k][j - inp[i].a] = compute(i, k, j - inp[i].a);
  long long maxi = -1;
  int pos = -1;
  long long cdiff;
  for (i = 0; i < m; ++i) {
    for (long long j = inp[i].a; j <= inp[i].b; ++j) {
      long long diff = j - inp[i].a;
      if (dp[i][n][diff].first > maxi) {
        maxi = dp[i][n][diff].first;
        pos = i;
        cdiff = diff;
      }
    }
  }
  if (pos == -1) {
    printf("NO\n");
    return 0;
  }
  vector<pair<int, long long> > ans;
  int cur = pos;
  ans.push_back(make_pair(inp[pos].id, inp[pos].a + cdiff));
  for (i = n - 1; i >= 1; --i) {
    int tcur = dp[cur][i + 1][cdiff].second.first;
    long long tdiff = dp[cur][i + 1][cdiff].second.second;
    cur = tcur;
    cdiff = tdiff;
    ans.push_back(make_pair(inp[cur].id, inp[cur].a + cdiff));
  }
  int sz = int((ans).size());
  cout << "YES\n";
  for (i = sz - 1; i >= 0; --i)
    cout << ans[i].first << " " << ans[i].second << endl;
  return 0;
}
