#include <bits/stdc++.h>
using namespace std;
const int inf = (int)1e9;
const int INF = 0x7fffffff;
const long long linf = 1LL << 60;
const int N = (int)1e5;
int n, m, p, q, a, b, c;
int fa[N + 5];
long long sum[N + 5];
int get(int u) {
  if (u != fa[u]) fa[u] = get(fa[u]);
  return fa[u];
}
void input() {
  scanf("%d %d %d %d", &n, &m, &p, &q);
  for (int i = (0), i_end_ = (n); i < i_end_; ++i) {
    fa[i] = i;
    sum[i] = 0;
  }
  for (int i = (0), i_end_ = (m); i < i_end_; ++i) {
    int val;
    scanf("%d %d %d", &a, &b, &val);
    --a;
    --b;
    int aa = get(a), bb = get(b);
    if (aa != bb) {
      fa[bb] = aa;
      sum[aa] += sum[bb];
    }
    sum[aa] += val;
  }
  c = 0;
  for (int i = (0), i_end_ = (n); i < i_end_; ++i) c += get(i) == i;
}
struct node {
  int x;
  bool operator<(const node &tmp) const { return sum[x] > sum[tmp.x]; }
};
priority_queue<node> Q;
void solve() {
  puts("YES");
  while (!Q.empty()) Q.pop();
  for (int i = (0), i_end_ = (n); i < i_end_; ++i)
    if (get(i) == i) Q.push((node){i});
  for (int i = (0), i_end_ = (c - q); i < i_end_; ++i) {
    int u = Q.top().x;
    Q.pop();
    int v = Q.top().x;
    Q.pop();
    u = get(u);
    v = get(v);
    sum[u] += sum[v] + min((long long)1e9, sum[u] + sum[v] + 1);
    fa[v] = u;
    Q.push((node){u});
    printf("%d %d\n", u + 1, v + 1);
    a = u;
    b = v;
  }
  p -= c - q;
  for (int i = (0), i_end_ = (p); i < i_end_; ++i)
    printf("%d %d\n", a + 1, b + 1);
}
int main() {
  input();
  if (c < q || c - q > p || (n == q && p > 0)) {
    puts("NO");
    return 0;
  }
  solve();
  return 0;
}
