#include <bits/stdc++.h>
using namespace std;
const long long N = 100000 + 10;
const long long INF = 1000000000;
long long v[N], pre[N];
long long n, m, p, q, tx, ty;
long long find(long long x) { return x == pre[x] ? x : pre[x] = find(pre[x]); }
int main() {
  while (scanf("%I64d%I64d%I64d%I64d", &n, &m, &p, &q) == 4) {
    tx = ty = -1;
    for (long long i = 1; i <= n; i++) {
      pre[i] = i;
      v[i] = 0;
    }
    while (m--) {
      long long i, j, k;
      scanf("%I64d%I64d%I64d", &i, &j, &k);
      tx = i;
      ty = j;
      i = find(i), j = find(j);
      if (i == j)
        v[j] += k;
      else {
        pre[i] = j;
        v[j] += v[i] + k;
      }
    }
    priority_queue<pair<long long, long long>,
                   vector<pair<long long, long long> >,
                   greater<pair<long long, long long> > >
        pq;
    long long cnt = 0;
    for (long long i = 1; i <= n; i++) {
      if (find(i) != i) continue;
      cnt++;
      pq.push(make_pair(v[i], i));
    }
    if (n == 1 && p > 0) {
      puts("NO");
      continue;
    }
    if (cnt < q) {
      puts("NO");
      continue;
    }
    if (p < cnt - q) {
      puts("NO");
      continue;
    }
    if (cnt == q && p > 0 && tx == -1) {
      puts("NO");
      continue;
    }
    puts("YES");
    long long re = cnt - q;
    p -= re;
    while (re--) {
      pair<long long, long long> p1 = pq.top();
      pq.pop();
      pair<long long, long long> p2 = pq.top();
      pq.pop();
      p1.first = min(INF, p1.first * 2ll + p2.first * 2ll + 1);
      printf("%I64d %I64d\n", p1.second, p2.second);
      tx = p1.second;
      ty = p2.second;
      pq.push(p1);
    }
    while (p--) {
      printf("%I64d %I64d\n", tx, ty);
    }
  }
  return 0;
}
