#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:16777216")
using namespace std;
const double PI = acos(-1.0);
const long long oo = 1000111000111000111LL;
struct rec {
  long long a, b;
  int c;
  int index;
} a[55];
bool operator<(rec a, rec b) { return a.c < b.c; }
int N, M, K;
long long f[55][55][111];
int tracej[55][55][111], tracek[55][55][111];
long long get(int i, int j, int k) {
  if (i == 1) return k + a[j].a;
  if (f[i][j][k] > -oo) return f[i][j][k];
  long long res = -oo + 1;
  for (int jj = (1), _b = (j); jj <= _b; jj++)
    if (a[jj].c < a[j].c) {
      long long cur = a[j].a + k;
      if (cur >= K) {
        long long prev = cur - K - a[jj].a;
        if (prev >= 0 && prev <= a[jj].b - a[jj].a) {
          long long now = get(i - 1, jj, prev) + cur;
          if (now > res) {
            res = now;
            tracej[i][j][k] = jj;
            tracek[i][j][k] = prev;
          }
        }
      }
      if (cur % K == 0) {
        long long prev = cur / K - a[jj].a;
        if (prev >= 0 && prev <= a[jj].b - a[jj].a) {
          long long now = get(i - 1, jj, prev) + cur;
          if (now > res) {
            res = now;
            tracej[i][j][k] = jj;
            tracek[i][j][k] = prev;
          }
        }
      }
    }
  return f[i][j][k] = res;
}
void trace(int i, int j, int k) {
  if (i == 0) return;
  trace(i - 1, tracej[i][j][k], tracek[i][j][k]);
  cout << a[j].index << ' ' << a[j].a + k << endl;
}
int main() {
  cin >> N >> M >> K;
  for (int i = (1), _b = (M); i <= _b; i++) {
    cin >> a[i].a >> a[i].b >> a[i].c;
    a[i].index = i;
  }
  sort(a + 1, a + M + 1);
  for (int i = (0), _b = (N); i <= _b; i++)
    for (int j = (0), _b = (M); j <= _b; j++)
      for (int k = (0), _b = (100); k <= _b; k++) f[i][j][k] = -oo;
  long long res = -1;
  int savej, savek;
  for (int j = (1), _b = (M); j <= _b; j++)
    for (int k = (0), _b = ((int)(a[j].b - a[j].a)); k <= _b; k++) {
      long long cur = get(N, j, k);
      if (cur > res) {
        res = cur;
        savej = j;
        savek = k;
      }
    }
  if (res == -1) {
    puts("NO");
  } else {
    puts("YES");
    trace(N, savej, savek);
  }
  return 0;
}
