#include <bits/stdc++.h>
using namespace std;
const int oo = 0x3f3f3f3f;
const long long OO = 1LL << 61;
const long long MOD = 1000000007;
long long dp[55][55][105];
struct DP {
  long long num, exer;
} pre[55][55][105];
struct SUBJ {
  long long a, b;
  int c;
  int id;
} sub[55];
long long num, exer;
int n, m;
long long k;
bool Dp() {
  memset(dp, -1, sizeof dp);
  memset(pre, -1, sizeof pre);
  for (int j = 1; j <= m; j++)
    for (long long x = sub[j].a; x <= sub[j].b; x++) {
      dp[1][j][x - sub[j].a] = x;
    }
  for (int i = 1; i < n; i++) {
    for (int j = 1; j <= m; j++) {
      for (long long x = sub[j].a; x <= sub[j].b; x++) {
        if (dp[i][j][x - sub[j].a] == -1) continue;
        for (int y = j + 1; y <= m; y++) {
          if (sub[y].c <= sub[j].c) continue;
          if (sub[y].a <= x + k && x + k <= sub[y].b) {
            if (dp[i + 1][y][x + k - sub[y].a] <
                dp[i][j][x - sub[j].a] + x + k) {
              dp[i + 1][y][x + k - sub[y].a] = dp[i][j][x - sub[j].a] + x + k;
              pre[i + 1][y][x + k - sub[y].a].num = j;
              pre[i + 1][y][x + k - sub[y].a].exer = x - sub[j].a;
            }
          }
          if (sub[y].a <= x * k && x * k <= sub[y].b) {
            if (dp[i + 1][y][x * k - sub[y].a] <
                dp[i][j][x - sub[j].a] + x * k) {
              dp[i + 1][y][x * k - sub[y].a] = dp[i][j][x - sub[j].a] + x * k;
              pre[i + 1][y][x * k - sub[y].a].num = j;
              pre[i + 1][y][x * k - sub[y].a].exer = x - sub[j].a;
            }
          }
        }
      }
    }
  }
  long long ans = -1;
  for (int j = 1; j <= m; j++) {
    for (long long x = sub[j].a; x <= sub[j].b; x++)
      if (dp[n][j][x - sub[j].a] != -1 && ans < dp[n][j][x - sub[j].a]) {
        ans = dp[n][j][x - sub[j].a];
        num = j;
        exer = x - sub[j].a;
      }
  }
  return ans != -1;
}
void output(int day, long long num, long long exer) {
  if (pre[day][num][exer].num == -1) {
    cout << sub[num].id << " " << exer + sub[num].a << endl;
    return;
  }
  output(day - 1, pre[day][num][exer].num, pre[day][num][exer].exer);
  cout << sub[num].id << " " << exer + sub[num].a << endl;
}
bool cmp(SUBJ s1, SUBJ s2) { return s1.c < s2.c; }
int main() {
  while (cin >> n >> m >> k) {
    for (int i = 1; i <= m; i++) {
      cin >> sub[i].a >> sub[i].b >> sub[i].c;
      sub[i].id = i;
    }
    sort(sub + 1, sub + 1 + m, cmp);
    if (Dp()) {
      puts("YES");
      output(n, num, exer);
    } else
      puts("NO");
  }
  return 0;
}
