#include <bits/stdc++.h>
using namespace std;
inline long long read() {
  long long x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + (ch ^ 48);
    ch = getchar();
  }
  return x * f;
}
const long long N = 100010;
struct node {
  long long x, c;
  bool operator<(const node& rhs) const { return c > rhs.c; }
};
priority_queue<node> que;
long long n, m, p, q, x, y, z, f[N], c[N], num;
inline long long anc(long long x) { return x == f[x] ? x : f[x] = anc(f[x]); }
inline void Union(long long x, long long y, long long z) {
  long long fx = anc(x), fy = anc(y);
  if (fx != fy) {
    f[fx] = fy;
    c[fy] += z + c[fx];
    --num;
  } else
    c[fx] += z;
}
signed main() {
  n = read();
  m = read();
  p = read();
  q = read();
  for (long long i = 1; i <= n; ++i) f[i] = i;
  num = n;
  for (long long i = 1; i <= m; ++i) {
    x = read();
    y = read();
    z = read();
    Union(x, y, z);
  }
  if (num - p > q || num < q || ((!(q - n) && p) && !m)) return puts("NO") & 0;
  puts("YES");
  for (long long i = 1; i <= n; ++i)
    if (anc(i) == i) que.push((node){i, c[f[i]]});
  while (num > q) {
    node x_csyakioi_1 = que.top();
    que.pop();
    node x_csyakioi_2 = que.top();
    que.pop();
    --p;
    --num;
    printf("%lld %lld\n", x_csyakioi_1.x, x_csyakioi_2.x);
    f[x_csyakioi_2.x] = x_csyakioi_1.x;
    c[x_csyakioi_1.x] +=
        min((long long)1e9, x_csyakioi_1.c + x_csyakioi_2.c + 1) +
        x_csyakioi_2.c;
    que.push((node){x_csyakioi_1.x, c[x_csyakioi_1.x]});
  }
  long long i;
  for (i = 1; i <= n; ++i)
    if (anc(i) != i) break;
  while (p--) printf("%lld %lld\n", i, f[i]);
  return 0;
}
