#include <bits/stdc++.h>
long long d[150000], dnum = 0, b[150000], l[150000], ans[150000][2], ann, n, m,
                     p, q, le;
long long findroot(long long x) {
  if (b[x] == x) {
    return x;
  } else {
    b[x] = findroot(b[x]);
    return b[x];
  }
}
int dadd(long long k) {
  long long i, j;
  dnum++;
  d[dnum] = k;
  i = dnum;
  while (i > 1 && l[d[i]] < l[d[i / 2]]) {
    j = d[i];
    d[i] = d[i / 2];
    d[i / 2] = j;
    i /= 2;
  }
  return 0;
}
long long dout() {
  long long an, i, j, k;
  an = d[1];
  d[1] = d[dnum];
  dnum--;
  i = 1;
  j = i * 2;
  if (j < dnum && l[d[j]] > l[d[j + 1]]) {
    j++;
  }
  while (j <= dnum && l[d[i]] > l[d[j]]) {
    k = d[i];
    d[i] = d[j];
    d[j] = k;
    i = j;
    j *= 2;
    if (j < dnum && l[d[j]] > l[d[j + 1]]) {
      j++;
    }
  }
  return an;
}
int main() {
  long long i, j, k, x, y, xx, yy, z;
  scanf("%I64d%I64d%I64d%I64d", &n, &m, &p, &q);
  for (i = 0; i < n; i++) {
    b[i] = i;
  }
  le = n;
  for (i = 0; i < m; i++) {
    scanf("%I64d%I64d%I64d", &x, &y, &z);
    x--;
    y--;
    xx = x;
    yy = y;
    x = findroot(x);
    y = findroot(y);
    if (x != y) {
      b[y] = x;
      l[x] += l[y];
      l[x] += z;
      le--;
    } else {
      l[x] += z;
    }
  }
  for (i = 0; i < n; i++) {
    if (b[i] == i) {
      dadd(i);
    }
  }
  if (q > le || (q == le && m == 0 && p > 0) || ((le - q) > p)) {
    printf("NO\n");
    return 0;
  }
  printf("YES\n");
  ann = 0;
  x = xx;
  y = yy;
  for (i = 0; i < (le - q); i++) {
    x = dout();
    y = dout();
    printf("%I64d %I64d\n", x + 1, y + 1);
    b[y] = x;
    z = l[x] + l[y] + 1;
    l[x] += l[y];
    if (z > 1000000000) {
      z = 1000000000;
    }
    l[x] += z;
    dadd(x);
  }
  for (i = le - q; i < p; i++) {
    printf("%I64d %I64d\n", x + 1, y + 1);
  }
  return 0;
}
