#include <bits/stdc++.h>
using namespace std;
int n, m;
int k;
bool debug = false;
struct subject {
  int c, i;
  long long a, b;
  bool operator<(const subject &o) const { return c < o.c; }
} s[55];
long long dp[55][55][105];
int K;
void pp() {
  long long ans = 0;
  pair<int, long long> av;
  for (int j = n; j <= m; j++)
    for (long long k = s[j].a; k <= s[j].b; k++)
      if (dp[n][j][k - s[j].a] > ans) {
        av = {j, k};
        ans = max(ans, dp[n][j][k - s[j].a]);
      }
  if (ans == 0) {
    puts("NO");
    return;
  }
  vector<pair<int, long long>> v;
  v.push_back(av);
  for (int i = n - 1; i > 0; i--) {
    av = v[n - 1 - i];
    bool bl = 1;
    for (int j = av.first - 1; j >= 0 && bl; j--)
      if (s[j].c < s[av.first].c)
        for (long long k = s[j].a; k <= s[j].b && bl; k++)
          if (dp[i][j][k - s[j].a] > 0)
            if (dp[i][j][k - s[j].a] + av.second == ans &&
                (K + k == av.second || K * k == av.second)) {
              v.push_back({j, k});
              ans = dp[i][j][k - s[j].a];
              bl = 0;
              break;
            }
  }
  puts("YES");
  reverse(v.begin(), v.end());
  for (auto x : v) printf("%d %lld\n", s[x.first].i, x.second);
}
int main() {
  cin >> n >> m >> K;
  for (int i = 1; i <= m; i++) {
    scanf("%lld%lld%d", &s[i].a, &s[i].b, &s[i].c);
    s[i].i = i;
  }
  sort(s + 1, s + 1 + m);
  for (int j = 1; j <= m; j++) {
    for (long long k = s[j].a; k <= s[j].b; k++) dp[1][j][k - s[j].a] = k;
  }
  for (int i = 2; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      for (int j2 = j + 1; j2 <= m; j2++)
        if (s[j2].c > s[j].c) {
          for (int k = 0; k <= 100; k++)
            if (dp[i - 1][j][k] > 0) {
              for (int k1 = 0; k1 <= 100; k1++) {
                long long x0 = k + s[j].a;
                long long x1 = k1 + s[j2].a;
                if (x0 > s[j].b || x1 > s[j2].b) continue;
                if (x0 + K == x1 || x0 * K == x1) {
                  if (dp[i - 1][j][k] + x1 > dp[i][j2][k1]) {
                    dp[i][j2][k1] = dp[i - 1][j][k] + x1;
                  }
                }
              }
            }
        }
    }
  }
  pp();
  return 0;
}
