#include <bits/stdc++.h>
using namespace std;
const double dinf = 1e200;
void mytimer(string task) {}
void ext(int c) {}
int gcd(int a, int b) { return a ? gcd(b % a, a) : b; }
struct item {
  long long a;
  int l;
  int c;
  int ind;
  void read() {
    long long t;
    cin >> a >> t >> c;
    l = t - a + 1;
  }
  bool operator<(const item &b) const { return c < b.c; }
};
int M, N, K;
item items[60];
long long dp[60][60][110];
pair<int, int> asdprev[60][60][110];
int main() {
  cin >> M >> N >> K;
  for (int i = 0; i < (N); ++i) {
    items[i].read();
    items[i].ind = i + 1;
  }
  sort(items, items + N);
  for (int n = 0; n < (N); ++n) {
    for (int v = 0; v < (items[n].l); ++v) dp[n][1][v] = items[n].a + v;
    for (int m = 2; m <= M; ++m) {
      for (int v = 0; v < (items[n].l); ++v) {
        for (int nn = 0; nn < (n); ++nn) {
          if (items[nn].c == items[n].c) continue;
          long long val;
          val = items[n].a + v - K;
          val -= items[nn].a;
          if (val >= 0 && val < items[nn].l) {
            int vv = (int)val;
            if (dp[nn][m - 1][vv] > 0) {
              long long t = dp[nn][m - 1][vv] + items[n].a + v;
              if (t > dp[n][m][v]) {
                dp[n][m][v] = t;
                asdprev[n][m][v] = make_pair(nn, vv);
              }
            }
          }
          long long tt = items[n].a + v;
          if (tt % K) continue;
          val = tt / K;
          val -= items[nn].a;
          if (val >= 0 && val < items[nn].l) {
            int vv = (int)val;
            if (dp[nn][m - 1][vv] > 0) {
              long long t = dp[nn][m - 1][vv] + items[n].a + v;
              if (t > dp[n][m][v]) {
                dp[n][m][v] = t;
                asdprev[n][m][v] = make_pair(nn, vv);
              }
            }
          }
        }
      }
    }
  }
  pair<long long, pair<int, int> > res(0, make_pair(0, 0));
  for (int n = 0; n < (N); ++n)
    for (int s = 0; s < (items[n].l); ++s)
      res = max(res, make_pair(dp[n][M][s], make_pair(n, s)));
  if (res.first == 0) {
    cout << "NO";
    return 0;
  }
  cout << "YES" << endl;
  pair<int, int> p = res.second;
  vector<pair<int, long long> > resv;
  int m = M;
  while (true) {
    resv.push_back(make_pair(items[p.first].ind, items[p.first].a + p.second));
    if (m == 1) break;
    p = asdprev[p.first][m][p.second];
    --m;
  }
  reverse(resv.begin(), resv.end());
  for (int i = 0; i < (int)resv.size(); ++i)
    cout << resv[i].first << ' ' << resv[i].second << '\n';
  return 0;
}
