#include <bits/stdc++.h>
using namespace std;
struct Point {
  int id;
  long long v;
  bool operator<(const Point &t) const { return v > t.v; }
};
const int maxn = 111111;
int fa[maxn], size[maxn];
long long dis[maxn];
int find(int a) { return fa[a] == a ? a : fa[a] = find(fa[a]); }
int join(int a, int b, long long c, int flag) {
  int x = find(a);
  int y = find(b);
  if (x == y)
    dis[x] += c;
  else {
    fa[x] = y;
    size[y] += size[x];
    if (!flag)
      dis[y] += dis[x] + c;
    else {
      dis[y] += min(dis[y] + dis[x] + 1, (long long)1e9) + dis[x];
    }
  }
  return y;
}
priority_queue<Point> Q;
int main() {
  int n, m, p, q;
  int i, j, k, a, b;
  long long c;
  cin >> n >> m >> p >> q;
  for (i = 1; i <= n; i++) fa[i] = i, size[i] = 1;
  for (i = 1; i <= m; i++) {
    cin >> a >> b >> c;
    join(a, b, c, 0);
  }
  int x = 0;
  for (i = 1; i <= n; i++) {
    if (fa[i] == i) {
      Point u;
      u.id = i, u.v = dis[i];
      Q.push(u);
      x++;
    }
  }
  Point u, e;
  if (x == q) {
    if (p == 0)
      puts("YES");
    else {
      int flag = 0;
      for (i = 1; i <= n; i++)
        if (fa[i] == i && size[i] > 1) {
          flag = i;
          break;
        }
      if (!flag)
        puts("NO");
      else {
        puts("YES");
        int last1 = flag, last2;
        for (i = 1; i <= n; i++)
          if (fa[i] == flag && i != flag) {
            last2 = i;
            break;
          }
        while (p) printf("%d %d\n", last1, last2), p--;
      }
    }
    return 0;
  }
  if (x < q || x - p > q)
    puts("NO");
  else {
    puts("YES");
    int last1, last2;
    while (x > q) {
      u = Q.top(), Q.pop();
      e = Q.top(), Q.pop();
      printf("%d %d\n", u.id, e.id);
      last1 = u.id, last2 = e.id;
      k = join(u.id, e.id, 0, 1);
      u.id = k, u.v = dis[k];
      Q.push(u);
      x--;
      p--;
    }
    while (p) printf("%d %d\n", last1, last2), p--;
  }
  return 0;
}
