#include <bits/stdc++.h>
using namespace std;
static vector<long long> vc1, vc2;
long long rec(long long n) {
  if (vc1[n] == n) return n;
  vc2[vc1[n]] += vc2[n];
  vc2[n] = 0;
  vc1[n] = rec(vc1[n]);
  return vc1[n];
}
int main() {
  ios_base::sync_with_stdio(0);
  long long n, m, p, q, x, y, l, a = 0, b;
  vector<set<long long> > vc;
  cin >> n >> m >> p >> q;
  vc.resize(n);
  vc1.resize(n);
  vc2.resize(n);
  priority_queue<pair<long long, long long>,
                 vector<pair<long long, long long> >,
                 greater<pair<long long, long long> > >
      pq;
  for (long long i = 0; i < n; ++i) {
    vc1[i] = i;
    vc2[i] = 0;
  }
  for (long long i = 0; i < m; ++i) {
    cin >> x >> y >> l;
    --x;
    --y;
    x = rec(x);
    y = rec(y);
    if (x != y) {
      vc2[x] += l;
      vc1[x] = y;
      rec(x);
    } else
      vc2[x] += l;
  }
  for (long long i = 0; i < n; ++i) {
    if (vc1[i] == i) pq.push(make_pair(vc2[i], i));
  }
  if (pq.size() - q > p || pq.size() < q) {
    cout << "NO" << endl;
    return 0;
  }
  q = pq.size() - q;
  vector<pair<long long, long long> > vc3;
  long long res = 0;
  for (long long i = 0; i < q; ++i) {
    a = pq.top().second;
    pq.pop();
    b = pq.top().second;
    pq.pop();
    vc3.push_back(make_pair(a, b));
    vc1[a] = b;
    rec(a);
    res += min(vc2[b] + 1, (long long)1000000000);
    vc2[b] += min(vc2[b] + 1, (long long)1000000000);
    pq.push(make_pair(vc2[b], b));
    --p;
  }
  for (long long i = 0; i < n; ++i)
    if (vc1[i] != i) {
      for (long long j = 0; j < p; ++j) vc3.push_back(make_pair(i, vc1[i]));
      p = 0;
      break;
    }
  if (p) {
    cout << "NO\n";
    return 0;
  }
  cout << "YES" << endl;
  for (long long i = 0; i < vc3.size(); ++i)
    cout << vc3[i].first + 1 << ' ' << vc3[i].second + 1 << '\n';
  return 0;
}
