#include <bits/stdc++.h>
using namespace std;
struct item {
  int node;
  long long sum;
  item(int node_, long long sum_) {
    node = node_;
    sum = sum_;
  }
  bool operator<(const item &a) const {
    if (sum != a.sum) return sum > a.sum;
    return node > a.node;
  }
};
priority_queue<item> que;
int root[100005];
long long sum[100005], rsum[100005];
int ans[100005][2], cnt;
int find(int x) {
  while (x != root[x]) x = root[x];
  return x;
}
void make(int x, int y) {
  while (1) {
    if (x == root[x]) {
      root[x] = y;
      return;
    }
    int tmp = root[x];
    root[x] = y;
    x = tmp;
  }
}
int main() {
  int n, m, p, q;
  scanf("%d%d%d%d", &n, &m, &p, &q);
  for (int i = 1; i <= n; i++) root[i] = i;
  while (m--) {
    int s, e, v;
    scanf("%d%d%d", &s, &e, &v);
    int a = find(s), b = find(e);
    if (a != b) {
      make(s, a);
      make(e, a);
    }
    sum[s] += v;
  }
  for (int i = 1; i <= n; i++) {
    rsum[find(i)] += sum[i];
  }
  for (int i = 1; i <= n; i++) {
    if (find(i) == i) {
      que.push(item(i, rsum[i]));
    }
  }
  if ((int)que.size() < q) {
    printf("NO\n");
    return 0;
  }
  if ((int)que.size() > p + q) {
    printf("NO\n");
    return 0;
  }
  while (1) {
    if (que.size() == q) break;
    if (que.size() < 2) {
      printf("NO\n");
      return 0;
    }
    item a = que.top();
    que.pop();
    item b = que.top();
    que.pop();
    ans[++cnt][0] = a.node;
    ans[cnt][1] = b.node;
    int x = find(a.node);
    make(a.node, x);
    make(b.node, x);
    long long v = min<long long>(1000000000, a.sum + b.sum + 1);
    que.push(item(x, a.sum + b.sum + v));
    p--;
    if (p == 0) break;
  }
  if (p > 0) {
    bool flag = 0;
    for (int i = 1; i <= n; i++) {
      if (find(i) != i) {
        flag = 1;
        break;
      }
    }
    if (flag == 0) {
      printf("NO\n");
      return 0;
    }
  }
  printf("YES\n");
  for (int i = 1; i <= cnt; i++) printf("%d %d\n", ans[i][0], ans[i][1]);
  if (p > 0) {
    for (int i = 1; i <= n; i++) {
      if (find(i) != i) {
        while (p--) printf("%d %d\n", i, find(i));
        break;
      }
    }
  }
  return 0;
}
