#include <bits/stdc++.h>
using namespace std;
priority_queue<pair<long long, int>, vector<pair<long long, int> >,
               greater<pair<long long, int> > >
    pq;
queue<pair<int, int> > ans;
int n, m, p, q;
int parent[111111];
long long dis[111111];
int find(int x) {
  if (parent[x] < 0) return x;
  parent[x] = find(parent[x]);
  return parent[x];
}
void union_root(int i, int j, long long cost) {
  if (i == j) {
    dis[i] += cost;
    return;
  }
  int temp = parent[i] + parent[j];
  if (parent[i] <= parent[j]) {
    parent[j] = i;
    parent[i] = temp;
    dis[i] = dis[i] + dis[j] + cost;
  } else {
    parent[i] = j;
    parent[j] = temp;
    dis[j] = dis[j] + dis[i] + cost;
  }
}
int main() {
  scanf("%d %d %d %d", &n, &m, &p, &q);
  for (int i = 1; i <= n; i++) {
    parent[i] = -1, dis[i] = 0;
  }
  for (int i = 0; i < m; i++) {
    int x, y;
    long long z;
    scanf("%d %d %I64d", &x, &y, &z);
    union_root(find(x), find(y), z);
  }
  for (int i = 1; i <= n; i++) {
    if (parent[i] < 0) {
      pq.push(make_pair(dis[i], i));
    }
  }
  if (pq.size() < q) {
    printf("NO");
  } else {
    int temp = pq.size() - q;
    if (temp > p) {
      printf("NO");
      return 0;
    }
    while (temp--) {
      pair<int, int> a = pq.top();
      pq.pop();
      pair<int, int> b = pq.top();
      pq.pop();
      ans.push(make_pair(a.second, b.second));
      p--;
      union_root(a.second, b.second, a.first + b.first + 1);
      a.second = find(a.second);
      a.first = dis[a.second];
      pq.push(a);
    }
    while (!pq.empty()) {
      pair<int, int> a = pq.top();
      pq.pop();
      if (parent[a.second] < -1) {
        int aa;
        for (aa = 1; aa <= n; aa++)
          if (parent[aa] == a.second) break;
        for (int i = 0; i < p; i++) ans.push(make_pair(a.second, aa));
        p = 0;
        break;
      }
    }
    if (p != 0) {
      printf("NO");
      return 0;
    }
    printf("YES\n");
    while (!ans.empty()) {
      printf("%d %d\n", ans.front().first, ans.front().second);
      ans.pop();
    }
  }
  return 0;
}
