#include <bits/stdc++.h>
using namespace std;
int fa[115000], ans1[115000], ans2[115000];
long long w[115000];
int _find(int x) { return fa[x] == x ? x : fa[x] = _find(fa[x]); }
struct CMP {
  bool operator()(int lft, int rht) { return w[lft] > w[rht]; }
};
priority_queue<int, vector<int>, CMP> que;
int main() {
  int n, m, p, q, ll = -1, rr = -1;
  scanf("%d%d%d%d", &n, &m, &p, &q);
  for (int i = 1; i <= n; ++i) fa[i] = i;
  int r = n;
  for (int i = 1, u, v, val; i <= m; ++i) {
    scanf("%d%d%d", &u, &v, &val);
    int x = _find(u);
    int y = _find(v);
    if (x == y)
      w[x] += val;
    else {
      fa[y] = x;
      w[x] += w[y] + val;
      r--;
    }
    ll = u;
    rr = v;
  }
  for (int i = 1; i <= n; ++i)
    if (i == _find(i)) que.push(i);
  int cnt = 0;
  bool f = false;
  if (r >= q && r - p <= q) {
    for (int i = 1; i <= r - q; ++i) {
      int u = que.top();
      que.pop();
      int v = que.top();
      que.pop();
      ans1[++cnt] = u;
      ans2[cnt] = v;
      fa[v] = u;
      w[u] += w[v];
      ll = u;
      rr = v;
      w[u] += min((long long)1000000000, w[u] + 1);
      que.push(u);
    }
    if (p - (r - q) == 0)
      f = true;
    else if (ll > 0)
      f = true;
    if (f) {
      for (int i = 1; i <= p - (r - q); ++i) ans1[++cnt] = ll, ans2[cnt] = rr;
    }
  }
  if (!f)
    printf("NO\n");
  else {
    printf("YES\n");
    for (int i = 1; i <= cnt; ++i) printf("%d %d\n", ans1[i], ans2[i]);
  }
  return 0;
}
