#include <bits/stdc++.h>
using namespace std;
int n, m, k, imp;
long long dp[51][52][52][103];
int nx[51][52][52][103];
struct sub {
  long long a, b, c, d;
} s[101];
bool comp(sub x, sub y) { return x.c < y.c; }
int code(int a, int b, int c, int d) {
  return a + b * 100 + c * 10000 + d * 1000000;
}
long long f(int cur, int no, int prev, int val) {
  long long& res = dp[cur][no][prev][val];
  int& ne = nx[cur][no][prev][val];
  if (res != -1) return res;
  if (no == n) return res = 0;
  if (n - no > m - cur) return res = -1000000007LL * 1000000007LL;
  res = f(cur + 1, no, prev, val);
  ne = code(cur + 1, no, prev, val);
  long long mi = s[cur].a, ma = s[cur].b;
  if (val == 101)
    for (long long i = mi; i < ma + 1; i++) {
      if (res < f(cur + 1, no + 1, cur, i - mi) + i) {
        res = f(cur + 1, no + 1, cur, i - mi) + i;
        ne = code(cur + 1, no + 1, cur, i - mi);
      }
    }
  else if (s[prev].c < s[cur].c) {
    long long p = s[prev].a + val;
    if (mi <= p + k && p + k <= ma) {
      if (res < f(cur + 1, no + 1, cur, p + k - mi) + p + k) {
        res = max(res, f(cur + 1, no + 1, cur, p + k - mi) + p + k);
        ne = code(cur + 1, no + 1, cur, p + k - mi);
      }
    }
    if (mi <= p * k && p * k <= ma) {
      if (res < f(cur + 1, no + 1, cur, p * k - mi) + p * k) {
        res = max(res, f(cur + 1, no + 1, cur, p * k - mi) + p * k);
        ne = code(cur + 1, no + 1, cur, p * k - mi);
      }
    }
  }
  return res;
}
int main() {
  cin >> n >> m >> k;
  for (long long i = 0; i < m; i++) {
    cin >> s[i].a >> s[i].b >> s[i].c;
    s[i].d = i + 1;
  }
  sort(s, s + m, comp);
  memset(dp, -1, sizeof(dp));
  long long res = f(0, 0, 0, 101);
  if (res < 0)
    cout << "NO";
  else {
    cout << "YES" << endl;
    vector<pair<int, long long> > ans;
    int a = 0, b = 0, c = 0, d = 101;
    while (b < n) {
      int nex = nx[a][b][c][d];
      int na = nex % 100, nb = nex / 100 % 100, nc = nex / 10000 % 100,
          nd = nex / 1000000;
      if (dp[na][nb][nc][nd] < dp[a][b][c][d]) {
        cout << s[a].d << " " << dp[a][b][c][d] - dp[na][nb][nc][nd] << endl;
      }
      a = na, b = nb, c = nc, d = nd;
    }
  }
}
