#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1.0);
const long long INF = 1e9;
const long long LINF = INF * INF;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int N = 50 + 7;
const int K = 100 + 7;
int n, m, koef;
struct predmet {
  long long a, b;
  int c;
  int id;
  void read(int i) {
    cin >> a >> b >> c;
    id = i;
  }
};
int cmp(predmet x, predmet y) {
  if (x.c != y.c) return x.c < y.c;
  return x.id < y.id;
}
predmet p[N];
long long dp[N][N][K];
pair<int, pair<int, int>> zvidky[N][N][K];
void onowy(int x1, int y1, int z1, int x2, int y2, int z2, long long val) {
  if (dp[x1][y1][z1] >= val) return;
  dp[x1][y1][z1] = val;
  zvidky[x1][y1][z1] = {x2, {y2, z2}};
}
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n >> m >> koef;
  for (int i = (1); i < (m + 1); ++i) p[i].read(i);
  memset(dp, -1, sizeof(dp));
  sort(p + 1, p + m + 1, cmp);
  for (int i = (1); i < (m + 1); ++i)
    for (int j = (0); j < (p[i].b - p[i].a + 1); ++j) dp[i][1][j] = p[i].a + j;
  for (int i = (1); i < (m + 1); ++i)
    for (int days = (1); days < (i + 1); ++days)
      for (int j = (0); j < (p[i].b - p[i].a + 1); ++j) {
        if (dp[i][days][j] == -1) continue;
        for (int k = (i + 1); k < (m + 1); ++k) {
          if (p[k].c == p[i].c) continue;
          long long moje = (p[i].a + j + koef);
          int l;
          if (moje >= p[k].a && moje <= p[k].b) {
            l = moje - p[k].a;
            onowy(k, days + 1, l, i, days, j, dp[i][days][j] + p[k].a + l);
          }
          moje = (p[i].a + j) * koef;
          if (moje >= p[k].a && moje <= p[k].b) {
            l = moje - p[k].a;
            onowy(k, days + 1, l, i, days, j, dp[i][days][j] + p[k].a + l);
          }
        }
      }
  long long ans = -1;
  for (int i = (1); i < (m + 1); ++i)
    for (int j = (0); j < (K); ++j) ans = max(ans, dp[i][n][j]);
  if (ans == -1)
    cout << "NO" << endl;
  else {
    cout << "YES" << endl;
    pair<int, pair<int, int>> zara;
    vector<pair<int, long long>> res;
    for (int i = (1); i < (m + 1); ++i)
      for (int j = (0); j < (K); ++j)
        if (ans == dp[i][n][j]) {
          zara = {i, {n, j}};
          break;
        }
    res.push_back({p[zara.first].id, p[zara.first].a + zara.second.second});
    for (int it = (0); it < (n - 1); ++it) {
      zara = zvidky[zara.first][zara.second.first][zara.second.second];
      res.push_back({p[zara.first].id, p[zara.first].a + zara.second.second});
    }
    reverse(res.begin(), res.end());
    for (auto i : res) cout << i.first << ' ' << i.second << endl;
  }
  cerr << "Time elapsed: " << clock() / (double)CLOCKS_PER_SEC << endl;
  return 0;
}
