#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007LL;
const int maxn = 100005;
int fa[maxn], n, m, p, q;
long long r[maxn];
vector<pair<int, int> > ans;
struct node {
  int r;
  long long v;
  node() {}
  node(int _r, long long _v) {
    r = _r;
    v = _v;
  }
  bool operator<(const node &n) const { return v > n.v; }
};
int find(int x) {
  if (x != fa[x]) fa[x] = find(fa[x]);
  return fa[x];
}
priority_queue<node> root;
int main() {
  scanf("%d %d %d %d", &n, &m, &p, &q);
  for (int i = 1; i <= n; i++) fa[i] = i, r[i] = 0LL;
  int u = -1, v, w;
  for (int i = 0; i < m; i++) {
    scanf("%d %d %d", &u, &v, &w);
    int ra = find(u), rb = find(v);
    if (ra == rb)
      r[ra] += w;
    else {
      fa[ra] = rb;
      r[rb] += r[ra];
      r[rb] += w;
      r[ra] = 0;
    }
  }
  for (int i = 1; i <= n; i++) {
    if (fa[i] == i) {
      root.push(node(i, r[i]));
    }
  }
  if (root.size() < q) {
    puts("NO");
    return 0;
  }
  for (int i = 0; i < p; i++) {
    if (root.size() > q) {
      node a = root.top();
      root.pop();
      node b = root.top();
      root.pop();
      ans.push_back(make_pair(a.r, b.r));
      a.v += min(a.v + b.v + 1, 1000000000LL);
      a.v += b.v;
      u = a.r, v = b.r;
      root.push(a);
    } else {
      if (u != -1) ans.push_back(make_pair(u, v));
    }
  }
  if (root.size() > q || ans.size() != p)
    puts("NO");
  else {
    puts("YES");
    for (int i = 0; i < ans.size(); i++)
      printf("%d %d\n", ans[i].first, ans[i].second);
  }
  return 0;
}
