#include <bits/stdc++.h>
using namespace std;
int n, m, k;
struct PP {
  int a, b, c;
} pre[55][55][105];
long long dp[55][55][105];
struct Task {
  long long a, b;
  int c, id;
  bool operator<(const Task &bb) const { return c < bb.c; }
} tt[55];
long long const inf = (long long)1 << 61;
int main() {
  while (cin >> n >> m >> k) {
    for (int i = 1; i <= m; i++) {
      cin >> tt[i].a >> tt[i].b >> tt[i].c;
      tt[i].id = i;
    }
    sort(tt + 1, tt + m + 1);
    for (int i = 1; i <= m; i++)
      for (int j = 0; j <= tt[i].b - tt[i].a; j++) {
        dp[1][i][j] = j + tt[i].a;
        pre[1][i][j].a = -1;
      }
    for (int i = 2; i <= n; i++) {
      for (int j = 1; j <= m; j++) {
        for (int s = 0; s <= tt[j].b - tt[j].a; s++) {
          dp[i][j][s] = -inf;
          for (int pj = 1; pj < j; pj++) {
            if (tt[pj].c >= tt[j].c) continue;
            long long tmp = tt[j].a + s - k;
            if (tmp >= tt[pj].a && tmp <= tt[pj].b) {
              int id = tmp - tt[pj].a;
              if (dp[i][j][s] < dp[i - 1][pj][id] + tt[j].a + s) {
                dp[i][j][s] = dp[i - 1][pj][id] + tt[j].a + s;
                pre[i][j][s].a = i - 1;
                pre[i][j][s].b = pj;
                pre[i][j][s].c = id;
              }
            }
            if ((tt[j].a + s) % k == 0) {
              tmp = (tt[j].a + s) / k;
              if (tmp >= tt[pj].a && tmp <= tt[pj].b) {
                int id = tmp - tt[pj].a;
                if (dp[i][j][s] < dp[i - 1][pj][id] + tt[j].a + s) {
                  dp[i][j][s] = dp[i - 1][pj][id] + tt[j].a + s;
                  pre[i][j][s].a = i - 1;
                  pre[i][j][s].b = pj;
                  pre[i][j][s].c = id;
                }
              }
            }
          }
        }
      }
    }
    int a, b, c;
    long long ma = -inf;
    for (int j = 1; j <= m; j++)
      for (int s = 0; s <= tt[j].b - tt[j].a; s++) {
        if (dp[n][j][s] > ma) {
          ma = dp[n][j][s];
          a = n;
          b = j;
          c = s;
        }
      }
    if (ma < 0) {
      puts("NO");
    } else {
      puts("YES");
      vector<int> ID;
      vector<long long> ex;
      while (a >= 0) {
        ID.push_back(tt[b].id);
        ex.push_back(tt[b].a + c);
        int ta, tb, tc;
        ta = pre[a][b][c].a;
        tb = pre[a][b][c].b;
        tc = pre[a][b][c].c;
        a = ta;
        b = tb;
        c = tc;
      }
      reverse(ID.begin(), ID.end());
      reverse(ex.begin(), ex.end());
      for (int i = 0; i < (int)ID.size(); i++)
        cout << ID[i] << ' ' << ex[i] << '\n';
    }
  }
}
