#include <bits/stdc++.h>
using namespace std;
long long a, s, d[100002], f[100002], g[100002], h, j, k, l, i, n, m;
vector<pair<int, int> > pas;
set<pair<long long, int> > q;
pair<long long, int> p1, p2;
pair<int, int> p;
int gpar(int idx) {
  if (d[idx] == idx) return idx;
  return d[idx] = gpar(d[idx]);
}
void dsu(int i1, int i2) {
  i1 = gpar(i1);
  i2 = gpar(i2);
  if (i1 == i2) {
    g[i1] += h;
    return;
  }
  d[i2] = i1;
  f[i1] += f[i2];
  g[i1] += g[i2];
  g[i1] += h;
  j--;
}
pair<int, int> src(int pr) {
  pair<int, int> ret = {0, 0};
  for (int i = 1; i <= n; i++) {
    if (gpar(i) == pr) {
      if (!ret.first)
        ret.first = i;
      else {
        ret.second = i;
        return ret;
      }
    }
  }
}
int main() {
  cin >> n >> m >> k >> l;
  j = n;
  for (i = 1; i <= n; i++) {
    d[i] = i;
    f[i] = 1;
  }
  for (i = 0; i < m; i++) {
    scanf("%d%d%d", &a, &s, &h);
    dsu(a, s);
  }
  if (j < l) {
    cout << "NO";
    return 0;
  }
  for (i = 1; i <= n; i++) {
    if (d[i] == i) q.insert({g[i], i});
  }
  for (i = 0; i < k; i++) {
    if (j > l) {
      p1 = *q.begin();
      q.erase(q.begin());
      p2 = *q.begin();
      q.erase(q.begin());
      h = min(1000000000ll, (p1.first + p2.first + 1));
      dsu(p1.second, p2.second);
      q.insert({g[p1.second], p1.second});
      pas.push_back({p1.second, p2.second});
    } else {
      if ((--q.end())->first == 0) {
        cout << "NO";
        return 0;
      }
      if (!p.first) p = src((--q.end())->second);
      pas.push_back(p);
    }
  }
  if (j != l) {
    cout << "NO";
    return 0;
  }
  cout << "YES\n";
  for (auto it : pas) {
    printf("%d %d\n", it.first, it.second);
  }
}
