#include <bits/stdc++.h>
using namespace std;
int n, m, p, q, nn, x, y, l;
int parent[100010];
long long d[100010];
int find_set(int v) {
  if (v == parent[v]) return v;
  return parent[v] = find_set(parent[v]);
}
bool unite(int a, int b, long long v) {
  a = find_set(a);
  b = find_set(b);
  if (a == b) {
    d[a] += v;
    return false;
  } else {
    d[a] += d[b] + v;
    parent[b] = a;
    return true;
  }
}
int main() {
  cin >> n >> m >> p >> q;
  for (int i = 1; i <= n; i++) parent[i] = i;
  nn = n;
  for (int i = 1; i <= m; i++) {
    cin >> x >> y >> l;
    if (unite(x, y, l)) nn--;
  }
  if (nn < q || p < nn - q || nn == n && q == n && p > 0) {
    cout << "NO";
    return 0;
  }
  int dif = nn - q;
  priority_queue<pair<long long, int> > pq;
  for (int i = 1; i <= n; i++)
    if (parent[i] == i) pq.push(make_pair(-d[i], i));
  cout << "YES\n";
  int same = p - dif;
  while (dif--) {
    int x = pq.top().second;
    pq.pop();
    int y = pq.top().second;
    pq.pop();
    cout << x << " " << y << "\n";
    unite(x, y, min((long long)1000000001 - 1, d[x] + d[y] + 1));
    x = find_set(x);
    pq.push(make_pair(-d[x], x));
  }
  int j = 1;
  for (int i = 1; i <= n; i++)
    if (parent[i] != i) {
      j = i;
      break;
    }
  int k = find_set(j);
  for (int i = 1; i <= same; i++) cout << k << " " << j << "\n";
  return 0;
}
