#include <bits/stdc++.h>
using namespace std;
int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};
int n, m, k;
vector<pair<pair<int, int>, pair<long long, long long> > > v;
long long dp[55][110][55][55];
bool f = 1;
long long solve(int idx, long long x, int cnt, int last) {
  if (cnt == n) return 0;
  if (idx == m) return 1e32;
  int y = x - v[last].second.first;
  long long &ret = dp[idx][x - v[last].second.first][cnt][last];
  if (ret != -1) return ret;
  ret = solve(idx + 1, x, cnt, last);
  if (v[idx].first.first > v[last].first.first) {
    if (x * k >= v[idx].second.first && x * k <= v[idx].second.second) {
      ret = max(ret, solve(idx + 1, k * x, cnt + 1, idx) + x * k);
    }
    if (x + k >= v[idx].second.first && x + k <= v[idx].second.second) {
      ret = max(ret, solve(idx + 1, k + x, cnt + 1, idx) + x + k);
    }
  }
  return ret;
}
void print(int idx, long long x, int cnt, int last) {
  if (cnt == n) return;
  if (idx == m) return;
  long long ret = dp[idx][x - v[last].second.first][cnt][last];
  if (ret == solve(idx + 1, x, cnt, last)) {
    print(idx + 1, x, cnt, last);
  } else if (v[idx].first.first > v[last].first.first) {
    if (x * k >= v[idx].second.first && x * k <= v[idx].second.second) {
      if (ret == solve(idx + 1, k * x, cnt + 1, idx) + x * k) {
        cout << v[idx].first.second << " " << x * k << "\n";
        print(idx + 1, k * x, cnt + 1, idx);
      }
    }
    if (x + k >= v[idx].second.first && x + k <= v[idx].second.second) {
      if (ret == solve(idx + 1, k + x, cnt + 1, idx) + x + k) {
        cout << v[idx].first.second << " " << x + k << "\n";
        print(idx + 1, k + x, cnt + 1, idx);
      }
    }
  }
  return;
}
int main() {
  cin.tie(0);
  std::ios::sync_with_stdio(false);
  cin >> n >> m >> k;
  v.resize(m);
  memset(dp, -1, sizeof dp);
  for (int i = 0; i < m; i++) {
    cin >> v[i].second.first >> v[i].second.second >> v[i].first.first;
    v[i].first.second = i + 1;
  }
  sort(v.begin(), v.end());
  long long mx = -1;
  long long x = 0, I = 0;
  for (int i = 0; i < m; i++) {
    for (long long j = v[i].second.first; j <= v[i].second.second; j++) {
      if (mx < solve(i + 1, j, 1, i) + j) {
        mx = max(mx, solve(i + 1, j, 1, i) + j);
        I = i;
        x = j;
      }
    }
  }
  if (mx != -1) {
    cout << "YES\n";
    cout << v[I].first.second << " " << x << "\n";
    print(I + 1, x, 1, I);
  } else
    cout << "NO\n";
}
