#include <bits/stdc++.h>
using namespace std;
struct data {
  int num;
  long long a, b, c;
} sb[55];
struct pa {
  int a, b;
};
int cmp(data a, data b) { return a.c < b.c; };
stack<long long> q;
long long f[55][55][105];
pa p[55][55][105];
long long ma1;
int n, m, k;
void dp() {
  memset(f, -1, sizeof(f));
  memset(p, -1, sizeof(p));
  f[0][0][0] = 0;
  for (int i = 1; i <= n; i++) {
    int s = min(i, m);
    long long dis = sb[i - 1].b - sb[i - 1].a;
    for (int j = 0; j <= s; j++) {
      for (int t = 0; t <= dis; t++) {
        if (j == 0) {
          f[i][j][t] = 0;
        } else if (j == 1) {
          f[i][j][t] = sb[i - 1].a + t;
        } else {
          long long ma = -1;
          long long path1 = -1;
          long long path2 = -1;
          for (int t1 = i - 1; t1 >= j - 1; t1--) {
            if (sb[t1 - 1].c == sb[i - 1].c) {
              continue;
            }
            long long tmp = sb[i - 1].a + t - k;
            if (tmp >= sb[t1 - 1].a && tmp <= sb[t1 - 1].b &&
                f[t1][j - 1][tmp - sb[t1 - 1].a] != -1) {
              if (ma < f[t1][j - 1][tmp - sb[t1 - 1].a] + sb[i - 1].a + t) {
                ma = f[t1][j - 1][tmp - sb[t1 - 1].a] + sb[i - 1].a + t;
                path1 = t1;
                path2 = 0;
              }
            }
            tmp = sb[i - 1].a + t;
            if (tmp % k == 0) {
              tmp /= k;
              if (tmp >= sb[t1 - 1].a && tmp <= sb[t1 - 1].b &&
                  f[t1][j - 1][tmp - sb[t1 - 1].a] != -1) {
                if (ma < f[t1][j - 1][tmp - sb[t1 - 1].a] + sb[i - 1].a + t) {
                  ma = f[t1][j - 1][tmp - sb[t1 - 1].a] + sb[i - 1].a + t;
                  path1 = t1;
                  path2 = 1;
                }
              }
            }
          }
          f[i][j][t] = ma;
          p[i][j][t].a = path1;
          p[i][j][t].b = path2;
        }
      }
    }
  }
  int tmp1 = -1;
  int tmp2 = -1;
  ma1 = -1;
  for (int i = m; i <= n; i++) {
    for (int j = 0; j <= 100; j++) {
      if (ma1 < f[i][m][j]) {
        ma1 = f[i][m][j];
        tmp1 = i;
        tmp2 = j;
      }
    }
  }
  int i1, i2, i3;
  i1 = tmp1;
  i2 = m;
  i3 = tmp2;
  while (i1 != -1) {
    q.push(sb[i1 - 1].a + i3);
    q.push(sb[i1 - 1].num);
    int tmp = p[i1][i2][i3].a;
    if (p[i1][i2][i3].b == 0) {
      i3 = i3 + sb[i1 - 1].a - k - sb[tmp - 1].a;
    } else {
      i3 = (i3 + sb[i1 - 1].a) / k - sb[tmp - 1].a;
    }
    i2--;
    i1 = tmp;
  }
}
int main() {
  while (cin >> m >> n >> k) {
    for (int i = 0; i < n; i++) {
      cin >> sb[i].a >> sb[i].b >> sb[i].c;
      sb[i].num = i + 1;
    }
    sort(sb, sb + n, cmp);
    ma1 = -1;
    dp();
    if (ma1 == -1) {
      cout << "NO" << endl;
    } else {
      cout << "YES" << endl;
      while (!q.empty()) {
        cout << q.top() << " ";
        q.pop();
        cout << q.top() << endl;
        q.pop();
      }
    }
  }
  return 0;
}
