#include <bits/stdc++.h>
using namespace std;
const int gg = 510001;
int size, tot, x, y, z, n, m, p, q, num[gg], u[gg], fa[gg], ans[gg][2];
long long heap[gg], team[gg];
int read() {
  int res = 0;
  char ch = getchar();
  while (ch < '0' || ch > '9') ch = getchar();
  while (ch >= '0' && ch <= '9') {
    res = res * 10 + (ch - '0');
    ch = getchar();
  }
  return res;
}
int find(int k) {
  if (fa[k] != k) fa[k] = find(fa[k]);
  return fa[k];
}
void put(long long d, int i) {
  int now, next;
  heap[++size] = d;
  num[size] = i;
  now = size;
  while (now > 1) {
    next = now >> 1;
    if (heap[next] <= heap[now]) return;
    swap(heap[next], heap[now]);
    swap(num[next], num[now]);
    now = next;
  }
}
void get() {
  int now, next;
  heap[1] = heap[size], num[1] = num[size--];
  now = 1;
  while (now * 2 <= size) {
    next = now * 2;
    if (heap[next] > heap[next + 1] && (next + 1 <= size)) next++;
    if (heap[next] >= heap[now]) return;
    swap(heap[next], heap[now]);
    swap(num[next], num[now]);
    now = next;
  }
  return;
}
void work() {
  int x1, x2, zz;
  long long y1, y2;
  for (int i = 1; i <= n; i++) {
    zz = find(fa[i]);
    if (!u[zz]) put(team[zz], zz);
    u[zz]++;
  }
  while (tot < p && size > q) {
    ++tot;
    x1 = num[1];
    y1 = heap[1];
    get();
    x2 = num[1];
    y2 = heap[1];
    get();
    put(y1 + y2 + min(y1 + y2 + 1ll, 1000000000ll), x1);
    fa[x2] = x1;
    ans[tot][0] = x1;
    ans[tot][1] = x2;
  }
  for (int i = 1; i <= n; i++) {
    zz = find(i);
    if (zz != i) {
      while (tot < p) {
        ++tot;
        ans[tot][0] = i;
        ans[tot][1] = zz;
      }
    }
    if (tot == p) break;
  }
  if (tot < p || size != q)
    printf("NO\n");
  else {
    printf("YES\n");
    for (int i = 1; i <= tot; i++) printf("%d %d\n", ans[i][0], ans[i][1]);
  }
}
int main() {
  scanf("%d%d%d%d", &n, &m, &p, &q);
  for (int i = 1; i <= n; i++) fa[i] = i;
  for (int i = 1; i <= m; i++) {
    x = read();
    y = read();
    z = read();
    int px = find(x), py = find(y);
    if (px != py) {
      fa[py] = px;
      team[px] += team[py] + z;
      team[py] = 0;
    } else
      team[px] += z;
  }
  work();
}
